tsue Posted November 30, 2013 Share Posted November 30, 2013 hello i need to use StringRegExp to get patterns like this "LLLAAMMDDXXX" "AAAAMMDD" "XXAADD" in specific strings it doesnt matter the order of the letters but i cant manage to read them from the strings Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico AAAAMMDD; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: XXAADD; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico XXAAMMDD; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico im trying with "(?s).*?([L]{14}|[A]{14}|[M]{14}|[D]{14}|[X]{14})" but i think im far from the answer, can anyone help me with this thanks in advance Link to comment Share on other sites More sharing options...
kylomas Posted November 30, 2013 Share Posted November 30, 2013 (edited) tsue, Can you provide more definition? The only discernable pattern I can see from what you've given is: - set = LAMDX - each part of set occurs more than one times edit: Most importantly, can you provide a real world example of the strings you are searching? Edited November 30, 2013 by kylomas Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
tsue Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) tsue, Can you provide more definition? The only discernable pattern I can see from what you've given is: - set = LAMDX - each part of set occurs more than one times edit: Most importantly, can you provide a real world example of the strings you are searching? each lineread has a unique combination of this symbols LAMDX some lines can have AAAA others DDDD, others AAXX but just a pattern for every lineread it will be somthing like this Text document has this lines: Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico AAAAMMDD; some blablablalba that i dont need Patrón: XXAADD o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico XXAAMMDD more blablabla that i dont need $fileopen = text.txt while 1 $toread = filereadline($fileopen) $array = StringRegExp($toread, $getXADMLforeachline , 3) msgbox(0, "found", "$array (AAA or AAMLLDD or depending the line)" wend fileclose ($fileopen) Edited November 30, 2013 by tsue Link to comment Share on other sites More sharing options...
kylomas Posted November 30, 2013 Share Posted November 30, 2013 tsue, $fileopen = text.txt Can you post 200-300 lines of this file? Forum Rules Procedure for posting code "I like pigs. Dogs look up to us. Cats look down on us. Pigs treat us as equals." - Sir Winston Churchill Link to comment Share on other sites More sharing options...
Solution Malkey Posted November 30, 2013 Solution Share Posted November 30, 2013 Here is my best quess of what you want. Local $sStr = "Patrón: LLLAAMMDDXXX en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico" & @CRLF & _ "AAAAMMDD; some blablablalba that i dont need" & @CRLF & _ ; "Patrón: XXAADD o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico" & @CRLF & _ ; "XXAAMMDD more blablabla that i dont need" MsgBox(0, "Results", StringRegExpReplace($sStr, ".*?([ADLMX]{3,}).*\v*", '"\1" ')) #cs Returns:- "LLLAAMMDDXXX" "AAAAMMDD" "XXAADD" "XXAAMMDD" #ce tsue 1 Link to comment Share on other sites More sharing options...
tsue Posted November 30, 2013 Author Share Posted November 30, 2013 (edited) tsue, Can you post 200-300 lines of this file? expandcollapse popupAAAAMM N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: LLLLAAMMDDXXX/LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres &o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: AAA N/A N/A Patrón: AAAA-999999999 (sin ceros a la izquierda) Patrón: 9 N/A Patrón: 9999 N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 Formato: AA N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A N/A N/A Formato: AA N/A Formato: AA Formato: Clave de región + número telefónico Patrón: ([A-Z][0-9]._-')+@([A-Z][0-9]._-')+ N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A Edited November 30, 2013 by tsue Added tags Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted November 30, 2013 Moderators Share Posted November 30, 2013 tsue,You have been here long enough to know that posting that much text without tags is not acceptable. Please do not do it again - and if you have fogotten how to do add the tags, see here. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
tsue Posted November 30, 2013 Author Share Posted November 30, 2013 Here is my best quess of what you want. Local $sStr = "Patrón: LLLAAMMDDXXX en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico" & @CRLF & _ "AAAAMMDD; some blablablalba that i dont need" & @CRLF & _ ; "Patrón: XXAADD o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico" & @CRLF & _ ; "XXAAMMDD more blablabla that i dont need" MsgBox(0, "Results", StringRegExpReplace($sStr, ".*?([ADLMX]{3,}).*\v*", '"\1" ')) #cs Returns:- "LLLAAMMDDXXX" "AAAAMMDD" "XXAADD" "XXAAMMDD" #ce yes this works really great thankyou is there a way with this line: Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad to just grab LLLLAAMMDDGEFCCC99 with StringRegExpReplace? right now im using global results so when it reads $regex[0] = AAAAAAAAAAAAAAAAAA it change it to $regex[1] because it has it as the second match $regex = StringRegExpReplace($sStr, ".*?([ADLMX]{1,99}).*v*", 3)) Link to comment Share on other sites More sharing options...
tsue Posted November 30, 2013 Author Share Posted November 30, 2013 tsue, You have been here long enough to know that posting that much text without tags is not acceptable. Please do not do it again - and if you have fogotten how to do add the tags, see here. M23 sorry Link to comment Share on other sites More sharing options...
mikell Posted November 30, 2013 Share Posted November 30, 2013 (edited) It's very difficult to understand the result(s) you exactly want to get Maybe this ? expandcollapse popup#Include <Array.au3> $txt = StringRegExpReplace(FileRead(@scriptfullpath), '(?s).+#cs(.+)#ce.*', "$1") $res = StringRegExp($txt, '.*Patr.n.*?([ADLMX]{3,}.*?)[\s;]', 3) _ArrayDisplay($res) #cs keep this comment ! AAAAMM N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: LLLLAAMMDDXXX/LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres &o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: AAA N/A N/A Patrón: AAAA-999999999 (sin ceros a la izquierda) Patrón: 9 N/A Patrón: 9999 N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 Formato: AA N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A N/A N/A Formato: AA N/A Formato: AA Formato: Clave de región + número telefónico Patrón: ([A-Z][0-9]._-')+@([A-Z][0-9]._-')+ N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A #ce Edited November 30, 2013 by mikell Link to comment Share on other sites More sharing options...
tsue Posted December 2, 2013 Author Share Posted December 2, 2013 (edited) It's very difficult to understand the result(s) you exactly want to get Maybe this ? expandcollapse popup#Include <Array.au3> $txt = StringRegExpReplace(FileRead(@scriptfullpath), '(?s).+#cs(.+)#ce.*', "$1") $res = StringRegExp($txt, '.*Patr.n.*?([ADLMX]{3,}.*?)[\s;]', 3) _ArrayDisplay($res) #cs keep this comment ! AAAAMM N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: LLLLAAMMDDXXX/LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres &o Ñ, AA=año, MM=mes, DD=día, X=alfanumérico Patrón: AAA N/A N/A Patrón: AAAA-999999999 (sin ceros a la izquierda) Patrón: 9 N/A Patrón: 9999 N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 Formato: AA N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA N/A N/A N/A Formato: AA N/A Formato: AA Formato: Clave de región + número telefónico Patrón: ([A-Z][0-9]._-')+@([A-Z][0-9]._-')+ N/A N/A N/A AAAAMMDD Patrón: LLLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AAAAAAAAAAAAAAAAAA Patrón: LLLLAAMMDDGEFCCC99; en donde, L=(A-Z) letra, AA=año, MM=mes, DD=día, G=M ó H, EF= Entidad federativa CC= (A-Z) letras 99=(0-9) número Formato: AA Formato: AA Patrón: 9999999 N/A Patrón: AAAAMMDD Patrón: LLLAAMMDDXXX; en donde, L=(A-Z) letra o caracteres & o Ñ, AA=año, MM=mes, DD=día, X= alfanumérico. Formato: AA Formato: 9999999 N/A #ce no, i need all but AAAAAAAAAAAAAAAAAA ill use if lineread[0] = AAAAAAAAAAAAAAAAAA then "use lineread[1] as it has the other pattern i need" Malkeys post is what i need yust thought i could do this too in a single regularexpression thanks Edited December 2, 2013 by tsue Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now