sourceSearch: regex with mode or flags

I am trying to use sourceSearch to look for a string in a way that is case insensitive.
I experimented with a regular expression but without success.

First I tried using the i flag as in regex=/string/i
That does not work because Kantu itself adds the slashes // around the regular expression of the user.

Next I tried to use a mode modifier specification in the regexp as in regex=(?i)string or regex=string(?i)
That does not work either. I get Invalid regular expression: …: Invalid group

Is there a way to make sourceSearch case insensitive?

Thanks

FYI my search string happens to be >a b</a and the regular expression reported by the error message is /(?i)>a b</a/

Hmm… I see the challenge here. (?i) is not supported in JS regex, you can’t make it partially case-sensitive. But I am sure we can find a workaround.

So what strings do you want to search for?

  • >a b</a/
  • >A b</a/
    >A B</a/
  • etc?

then this should work regex=>[aA] [bB]</[aA]/

For example, regex=[aA]9[tT]9 matches a9t9, A9T9, A9t9 and a9T9.

Thanks for your fast response!

If it only were that simple. a b in this case represents a first name and a last name. I will have to loop over many names: a b, John Doe, jane doe, karla Marks, ABE LINCOLN, etc. Hence the string is not all that predictable.

By the way, I did manage to use regexp with storeEval, and case insensitive works there with /…/i Maybe instead of sourceSearch, as a workaround, I can dump the full html into a variable and then apply storeEval.

Ok, got it. In any case, the real solution will be to slightly change the syntax of sourceSearch, so that a command like regex=/string/i works => I created a ticket for this.

1 Like

Solved: How to sourceSearch and sourceExtract with case-insensitve text - #4 by admin