Regex ignore multiple wrong placed quotes


Regex ignore multiple wrong placed quotes



From this input:


""" "01-01-2000""" " ",""" "Bank123""" "", "" ""Example text" " "",



I want to extract:


01-01-2000
Bank123
Example text



I managed this:


(["'])(?:(?=(?))2.)*?1



But if fails if it comes to deal with many wrong placed quotes. Any ideas?





Try "b(.*?)b"
– Wiktor Stribiżew
Jun 29 at 8:41


"b(.*?)b"





Or, B"b(.*?)b"B. Can the values you want to extract contain "? Why did you use a regex that matches escaped "?
– Wiktor Stribiżew
Jun 29 at 8:48



B"b(.*?)b"B


"


"





Could you please clarify?
– Wiktor Stribiżew
Jun 29 at 9:57




3 Answers
3



As I see, you are interested in strings which:


"



So the intuitive solution is [a-zd][^"]* with gi options
(global, case insensitive).


[a-zd][^"]*


gi



For your given example, perhaps it could be an option to match a whitespace or a double quote zero or more times [ "]* to match what comes before the value between the inner double quotes.


[ "]*



Then match that double quote and capture in a group not a double quote or a newline ([^"rn]+) using a negated character class.


([^"rn]+)



At the end match the closing double quote followed by zero or more times a whitespace or a double quote which will match what comes after so the group does not match a whitespace between double quotes.



[ "]*"([^"rn]+)"[ "]*


[ "]*"([^"rn]+)"[ "]*



There are various options to do so:


1) ([d-ws][d-ws]+)
2) ([d-ws]{2,})
3) "b(.+?)b"
4) b([^"]{2,})b



Demo : https://regex101.com/r/jPXqKv/1



Test:


""" "01-01-2000""" " ",""" "Bank123""" "", "" ""Example text" " ""



Match:


Match 1
Full match 5-15 `01-01-2000`
Group 1. 5-15 `01-01-2000`
Match 2
Full match 28-35 `Bank123`
Group 1. 28-35 `Bank123`
Match 3
Full match 48-60 `Example text`
Group 1. 48-60 `Example text`






By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

Export result set on Dbeaver to CSV

Opening a url is failing in Swift