By using Regular Expressions how can I extract all text in double quotes, and all words out of quotes in such string:
01AB "SET 001" IN SET "BACK" 09SS 76 "01 IN" SET
First regular expression should extract all text inside double quotes like
SET 001
BACK
01 IN
Second expression shoud extract all other words in string
01AB
IN
SET
09SS
76
SET
For the first case works fine ("(.*?)")
. How can I extract all words out of quotes?
To extract strings in between the quotations we can use findall() method from re library.
The re.search() function will search the regular expression pattern and return the first occurrence. Unlike Python re. match(), it will check all lines of the input string. If the pattern is found, the match object will be returned, otherwise “null” is returned.
Try this expression:
(?:^|")([^"]*)(?:$|")
The groups matched by it will exclude the quotation marks, because they are enclosed in non-capturing parentheses (?:
and )
. Of course you need to escape the double-quotes for use in C# code.
If the target string starts and/or ends in a quoted value, this expression will match empty groups as well (for the initial and for the trailing quote).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With