I am trying to write a regular expression to do a find and replace operation. Assume Java regex syntax. Below are examples of what I am trying to find:
- 12341+1
- 12241+1R1
- 100001+1R2
So, I am searching for a string beginning with one or more digits, followed by a "1+1" substring, followed by 0 or more characters. I have the following regex:
^(\d+)(1\\+1).*
This regex will successfully find the examples above, however, my goal is to replace the strings with everything before "1+1"
. So, 12341+1 would become 1234, and 12241+1R1 would become 1224. If I use the first grouped expression $1
to replace the pattern, I get the wrong result as follows:
- 12341+1 becomes 12341
- 12241+1R1 becomes 12241
- 100001+1R2 becomes 100001
Any ideas?