ssborbis / ContextSearch-web-ext

Search engine manager for modern browsers
337 stars 37 forks source link

How to modify {searchTerms} with REGEX #675

Open wxlg1117 opened 8 months ago

wxlg1117 commented 8 months ago

some source searchTerms:

ccccc00176 ccccc176 1aaaaa00532 1ff830
1wwwww670 13rrrr01177 48qqqqq054 48qqqqq00054 41eeee21678 125kkk823 125kkk00823 5530ii009 5530jj00009 5642eeee21678 m_086llll42 n_086llll00042 t_1100dddd209 y_1248eeeee00234 u_1428gg050 p_1231hh00050

I need to take the middle string of consecutive characters and the rightmost section of consecutive numbers, and connect them with - (if there is a 0 or 2 zeros between the character and the last non-zero number, they must be removed): regexspl

I tried to write a lookup regular expression, FINDREGEX: ` ([a-zA-Z]\d+|\d*)([a-zA-Z]+)0{0,2}(\d{1,5}) `

REPLACE_REGEX: \2-\3

I tried to write a lookup regular expression using () to define the grouping, but I can't use \n to reference the grouping in the replacement regular expression.

Can anyone help me with how to write a regular expression? Thank you in advance.

ssborbis commented 8 months ago

Something like this?

/([a-zA-Z]_\d+|\d*)([a-zA-Z]+)0{0,2}(\d{1,5})/$2-$3/g

image