ContextSearch-web-ext icon indicating copy to clipboard operation
ContextSearch-web-ext copied to clipboard

How to modify {searchTerms} with REGEX

Open wxlg1117 opened this issue 1 year ago • 1 comments

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, FIND_REGEX: ([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.

wxlg1117 avatar Jan 14 '24 18:01 wxlg1117

Something like this?

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

image

ssborbis avatar Jan 18 '24 06:01 ssborbis