Home > Blockchain >  Regex to find out a substring that starts with a space and ends with a substring
Regex to find out a substring that starts with a space and ends with a substring

Time:09-30

I am currently new to Regex, can someone help me with it? So the text that I have is the following:

yolo _time<=$info_max_time$ (index=* OR index=_*) $threat_match_value$ [search _time=2022-09-26T11:17:12.000-07:00 index=threat_activity   | head 1 | `makemv(orig_sourcetype)` | rename orig_sourcetype as sourcetype | mvexpand sourcetype | return 100 sourcetype]

I want a regex that finds out the string for example, given that it starts with a space and match ends when it gets the provided substring

_time<=$info_max_time$

So I have $info_max_time$, I want to search for the string which starts with a space and ends with $info_max_time$. Now in between it can have any characters, _ , = or <= or >="

CodePudding user response:

You may use:

\s\S ?\$info_max_time\$

Demo.

Details:

  • \s - A whitespace character.
  • \S ? - One or more non-whitespace characters (non-greedy quantifier).
  • \$info_max_time\$ - Match "$info_max_time$" literally.

Note that \s will match any whitespace characters (e.g., tab, EOL, etc.). If you're only interested in the ASCII space (AKA ), you may use the following instead:

[ ][^ ] ?\$info_max_time\$
  • Related