regex - Verify if provided string corresponds to pattern on python -
Would you please advise how to confirm in the python if the provided string returns the returned patterns and returns Corresponds to
For example, the following are the patterns given:
& lt; [Prefix] - [ID]> 'separated by', '> | & Lt; Log> "
Where the prefix is any number of characters, the id is only numbers but not more than 5 digits, any number of logs is any letter
Example: < / P>
-
proj-123 | log message
-
prog-2334, prose-345 | log message
I think the easiest way is to implement regexp that I did not use on the python.
Thanks.
(?: [Az] + - \ d {1,5}) (?: [Az] + - \ d { 1,5}) * \. *. *
< P> It is not clear what you want to capture, so I use non-capturing groups. If you only need boolean: & gt; & gt; & Gt; Regex = '[az] + - \ d {1,5} (?:, [Az] + - \ d {1,5}) *. *' * 'Gt; & gt; regex , 'PROJE 234, PROJE-45 | LOG message') is not true
Of course, the same results can be obtained from the order of simple string methods:
Prefs.split (',') for the group prefs, _, log = subj.partition ('|'): pref, _, id5 = group.partition (' - ') if id5.isdigit () and lane (id5) & lt; = 5 and pref.isalpha (): print (pref, id5)
Comments
Post a Comment