1

I have strings as follows

  • 5V6A 6Q2A 6Q 5Q
  • FA 7A EQ2A 799Q
  • M Y77A279791
  • V59 2 5A266
  • Q7Q E7Q 7 7AQ2A 7A29

I identify them using following in Find Option

\w.+\d.+(\w+( |$))+

My problem is that I want to replace it with same, but add a "@" symbol afterwards. I want find-replace in Sublime Text / Notepad++. I want to retain what I find, replace with same, but with a "@" at the end of it. So at the end, I want it to be as follows after replacement.

  • 5V6A 6Q2A 6Q 5Q @
  • FA 7A EQ2A 799Q @
  • M Y77A279791 @
  • V59 2 5A266 @
  • Q7Q E7Q 7 7AQ2A 7A29 @

Please help with replace.

Example of Data I want to find them in

5V6A 6Q2A 6Q 5Q
Ms.Elena O Peery
Abell (Baltimore)
$Six Million  One Hundred Thirty Thousand Seven Hundred Thirty Nine AND Twenty Six%
Twenty Nine Years AND Seven.One%
(Purchase Value Reduction 16.47%)
(Monthly Principal Reduction 7.59%)
(Total Interest Reduction 17.81%) 
Mr. Guy L Pittman   
E97 99A2A 7Q 9A2999Q

 Q5A2A5 6 6A 5 767Q 
 Mrs.Margaret E No Lents
 Juction(Portland) 
 $Seven Million Nine Hundred Eighty Six Thousand Three Hundred Twenty Three     AND Seventeen%
 Seventeen Years AND Seven.Eight%
(Purchase Value Reduction 2018%)
(Monthly Principal Reduction 1036%)
(Total Interest Reduction 14.87%) 
Ms.Edna R Messerly 
7A2YA2AQ27A 7A27AQ2
VIVEK
  • 15
  • 7
  • What's the rule for matching above strings ? –  Mar 24 '16 at 12:55
  • \w.+\d.+(\w+( |$))+ seems to work mostly. You can suggest if there are better ones :) – VIVEK Mar 24 '16 at 12:56
  • I mean they are just Upper case characters, number and space at random positions. Check my [Demo](https://regex101.com/r/tN2tA6/2). Is this what you are looking for ? –  Mar 24 '16 at 12:57
  • searching `$` and replacing with ` @` works prefectly in notepad++ for all samples - but i doubt a bit that that's what you want – Sebastian Proske Mar 24 '16 at 12:59
  • @SebastianProske I dont think those strings occur at end of lines, i think they can be in between as well – riteshtch Mar 24 '16 at 13:01
  • @noob , your solution seems to work. thanks. but that it has other words between them, so they are getting replaced too, for example : F66 64 7376 7 "@" - I want @ here Mr.Howard M Adams Jonesville,AK $Six Million Three Hundred Sixty Seven Thousand Fifty AND Nineteen% Thirteen Years AND Nine.Five% (Purchase Value Reduction 19.47%) (Monthly Principal Reduction 5.56%) (Total Interest Reduction 10.47%) Ms.Kathryn J Mite V9A27AQ2M Y M Y99 7 "@" - I want @ here – VIVEK Mar 24 '16 at 13:04
  • Please provide additional strings you want to **match** and some you do **not want to be matched**. As the question stands, it's somewhat unclear. – Jan Mar 24 '16 at 13:05
  • I still don't get the criteria for making up the regex but if your regex works fine then search for `(\w.+\d.+(\w+( |$))+)` and replace with `\1 @` in notepad++ – riteshtch Mar 24 '16 at 13:06
  • @VIVEK: I think you should give proper details in the question. I can see that you are a new user on this site. Without details one is not going to assume anything else. –  Mar 24 '16 at 13:08
  • @ritesht93 : It Worked. Thanks !! – VIVEK Mar 24 '16 at 13:10

3 Answers3

0

In Sublime Text try this (\w.+\d.+(?:\w+(?: |$))+) in find box and this in $1 @ replace box.

sehrob
  • 1,034
  • 12
  • 24
0

Just posting it as an answer to mark the question solved.

I still don't get the criteria for making up the regex but if your regex works fine then search for (\w.+\d.+(\w+( |$))+) and replace with \1 @ in notepad++

riteshtch
  • 8,629
  • 4
  • 25
  • 38
  • This is ***very*** ineffective and likely to fail soon because of the nested quantifiers. Your expression needs [**19000 (sic!) steps**](https://regex101.com/r/eT7pA7/4) for a rather short text - what is it supposed to do when handling a *real* text? – Jan Mar 24 '16 at 13:19
  • @Jan Yes I know, regex was not formed by me, the input text wasn't specified, also the regex matching criteria wasnt specified until very late after OP edited the question, i posted this answer as a comment as a quick fix – riteshtch Mar 24 '16 at 13:23
0

In your example, the following "criteria" might help:

^((?>\h?(?>[A-Z0-9]+)\h?)+)$
# ^ and $ - bind to beginning and end of the line in multiline mode
# the rest matches uppercase letters and digits 
# plus an optional whitespace at the beginning / end of the line
# ... and puts them in atomic groups

See an example on regex101.com.

Jan
  • 42,290
  • 8
  • 54
  • 79