ICU Regex matching for non-digit and no whitespace

109 views Asked by At

I am trying to help the readability in my terminal and thought I'd create a trigger highlight for when I use binding.pry.

The regex I used to match any <% binding.pry %> is:

(?i:.*<% binding.pry %>.*)

This works great, but wanted to take it one step further and only highlight the current binding.pry in the terminal (in case I may have multiples that display in the terminal).

How might I write my ICU regex so the following outputs correctly:

    64:       <div class="form-group">
 => 65:         <% binding.pry %>  # This one should match
    66:       </div>
    67:       <% binding.pry %>  # This one should not be matched

I know I want to match a string that includes the => as well as the <% binding.pry %> but negate the whitespace and numbers. The closest approach I thought would work was (?:\S+[^0-9].*=><% binding.pry %>) but this unfortunately did not work.

2

There are 2 answers

0
Hasan On

Unless I understood your last paragraph incorrectly, (?m:^ => \d+:\s*<% binding.pry %>.*) should do what you want.

It only matches the => 65: <% binding.pry %> # This one should match line.

See it in action here

0
mikeymurph77 On

After some tinkering I was able to get a match by using the following regex:

(=>.*)(:.*binding.pry %>)

This satisfys my intention to only match => 65: <% binding.pry %>