Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My data is underscore-delimited like this for example:

A_B_C_D_E

Regex 1 I need to match: A__C_D_E

Regex 2 I need to match: A_B__D_E

Regex 3 I need to match: A_B_C__E

A little background on this. I'll be replacing the regex matches with empty.string thus leaving me with the value of each column. Example, regex 1 would leave me with the value B when the match is replaced by empty.string. IMPORTANT: ABCDE are all dyanmic data...they are not literally ABCDE. The underscore delimiter is literal. The number of "columns" delimited by this underscore is constant.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
431 views
Welcome To Ask or Share your Answers For Others

1 Answer

For case 1:

Search using:

^([^_]*_)[^_]*

And replace by:

$1

RegEx Demo 1


For case 2:

Search using:

^((?:[^_]*_){2})[^_]*

And replace by:

$1

RegEx Demo 2


For case 3:

Search using:

^((?:[^_]*_){3})[^_]*

And replace by:

$1

RegEx Demo 3


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...