|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
||||
|
||||
|
regular expression
Hi all,
short question concering a regular expression pattern. Code:
line = '1 "bla \"bla\" $%1!\n" $ just "a" test'
rexEntry = re.compile('^(\d+)\s"(.*)" *(\$.*)?')
mo = rexEntry.match(line)
print mo.groups()
With this I get the following result: Code:
('1', 'bla \"bla\" $%1!\n" $ just "a', None)
But that what I want is: Code:
('1', 'bla \"bla\" $%1!\n', '$ just "a" test')
Can someone give me a hint? Thanks in advance! |
|
#2
|
||||
|
||||
|
This works for me... with the example above.
Code:
^([0-9]+)\t"(.+)"\s(\$.+?)$ Note: If you use this with match you shouldnt have to have the ^ at the beginning. Hope this helps, Mark. |
|
#3
|
||||
|
||||
|
Thank you for your reply.
Your code works for the example above but there are still cases in my problem that can't be matched with this pattern. I solved the problem by specifying two patterns and combined them with | That works now for me... ... I always use ^ if I want to find a string at the beginning. I know that just "match" will do it also but ... ... I don't know ... habit |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > regular expression |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|