1

I need to find a regular expression that will work with the following dummy input:

Lorem ipsum dolor sit -V amet, consectetuer adipiscing elit. 
Aenean commodo ligula Charge Tip eget dolor. Aenean massa. 
Cum sociis natoque penatibus et magnis dis parturient montes.
Nascetur ridiculus Charge Tip mus. Donec quam felis,-Vultricies nec.
Pellentesque eu, pretium quis, sem. Nulla consequat massa.
Quis enim. DonecCharge Tippede justo, fringilla vel, aliquet nec.-V
Vulputate eget, arcu. In enim justo, rhoncus ut.

And produce the following result:

Charge Tip -V
Charge Tip -V

Some notes:

  • Charge Tip is always before -V
  • Charge Tip may be attached to other data on the left and right.
  • -V may be attached to other data on the left and right

I tried many links here already, such as: Regular expression to find two strings anywhere in input

I was unable to get any solution to work as the solutions fail to work on the RegExr site, which I am using to test the regex.

The final result I need is for the regex to work inside Agent Ransack 2014, as I need to search log files on a Windows XP machine.

Community
  • 1
  • 1
wickyd
  • 277
  • 1
  • 11

2 Answers2

3

Agent Ransack regex engine is Perl compatible. So you can easily search for:

(?-s)Charge Tip(?=.*-V)|(?!\A)\G.*\K-V

Live demo

revo
  • 47,783
  • 14
  • 74
  • 117
  • Thank you. If possible, please modify it slightly to highlight the -V, as there are many lines with charge Tip without -V, and your solution looks like Charge Tip only. – wickyd Mar 18 '17 at 08:18
  • You're welcome. You may consider up-voting this answer as well if it helped you. – revo Mar 18 '17 at 08:37
  • Done. It most certainly did. – wickyd Mar 18 '17 at 08:39
0

Try the following regex, you can see it live here:

^[\w \,\.]*(Charge Tip)[\w \,\.]*(\-V)[\w \,\.]*$

As seen here:

Regex101

JosephGarrone
  • 4,081
  • 3
  • 38
  • 61
  • Unfortunately this doesn't give any matches, on regex101 or regexr. – wickyd Mar 18 '17 at 08:15
  • @wickyd can you please explain where it doesn't match? See my edit for what I see on Regex101. – JosephGarrone Mar 18 '17 at 08:18
  • @wickyd Looks like it didn't save correctly. See the `g` on the far right of the regex line, if you add an `m` (multiline) it should work. IE: `/^[\w \,\.]*(Charge Tip)[\w \,\.]*(\-V)[\w \,\.]*$/gm` – JosephGarrone Mar 18 '17 at 08:25
  • This way you highlight whole line in Agent Ran. not just `Charge Tip` and `-V` – revo Mar 18 '17 at 08:32
  • @revo I'm not sure what you are talking about? The regex will provide two matches - "Charge Tip" and "-V". – JosephGarrone Mar 18 '17 at 08:33
  • No it doesn't. It matches *whole line* and *captures* `Charge Tip` and `-V` accordingly – revo Mar 18 '17 at 08:36
  • The question asks to produce the `Charge Tip -V` result. This can be done with `\1` and `\2`. – JosephGarrone Mar 18 '17 at 08:38
  • Where in Agent Ran. should OP use these back-references? Is he trying to do a find / replace? Does the program provide a find / replace functionality at all? – revo Mar 18 '17 at 08:43