I need a regex to process the keywords from a search field. The idea is to have it act very much like google (ie: support double quoted text to allow for terms with spaces). Further, I have tags in my dataset that I would like to be able to reference using a color.
A sample input would be:
select <stuff> from <table>
where replace(replace(upper(id), 'I', '1'), 'O', '0') like '%<number-search-term>%'
This should output:
1/2 one two "three & four" five:six seven:"eight nine ten"
It would also work fine to have 'five' and 'seven' in the same capture group as the other keywords as long as there is another capture group associated with 'six' and 'eight nine ten'.
答案 0 :(得分:0)
Regex:
Extension server_name, server_name: [type=host_name (0), value=site.company.com]
Substitution:
((\"[\s\S]+?\")|[\s\S]+?(:(?2))?)\K(\s+|$)
Explanation:
Get everything and possibly everything in-between quotes (starting with either spaces or a \r\n
), then resets the regex matching, and then matches any spaces or end of the string. This means that it only matches the spaces or end of string and then replaces it with a newline.
Use:
:
Demo: https://regex101.com/r/jO4oM0/3
Edit 1: Improved as wasn't properly matching everything properly
Edit 2: Shortened