'Find and Replace' question
-
Hello!
Need lots of editing from say PR1=‘0066’ or PR1=‘3601’ or PR1=‘3722’ … to same, but without quotation marks and wise versa.
Is there any way to do it with help of find and replace? -
taking your short description, you could use regular expression in find/replace.
(?<=PR1=)'*\d+'*
which means regex is looking for numbers which are/aren’t encased by single quotes and must be prefixed by PR1= .
In replace put the number you want to have.
Cheers
Claudia -
Thank you so much Claudia!
That code actually works and finds all the instances it supposed to.
But I have problems with replacement now…
It should be same numbers with same sequence, just without quotes - like, PR1=‘0066’ or PR1=‘3601’ or PR1=‘3722’… after replacement should be -> PR1=0066 or PR1=3601 or PR1=3722…
Is it possible to make find and replace to leave the same numbers after adding or deleting quotes?
Mb there is other way to add/delete quotes in sequence where PR1= is constant, but numbers are different and just randomly assigned? -
you just wanna get rid of the single quotes?
PR1= and number should stay?Cheers
Claudia -
That`s correct. PR1=and number should stay for each instance of PR1=number1, PR1=number2 …PR1=numberN
-
not the most elegant but in find what use
(?<=PR1=)(')(\d+)(')
and in replace with use backslash 2
\2
Cheers
Claudia -
@Claudia-Frank said:
(?<=PR1=)(')(\d+)(')
and in replace with use backslash 2
\2
Cheers
ClaudiaThank you so so much! Pure magic! :)
-
you’re welcome - but if you really wanna see pure magic checkout
the regex tips from guy038 and the other regex gurus :-DCheers
Claudia -
That`s my plan :)
-
Hello @oleg-nemchenko, @claudia-frank and All,
Or even more simple :
SEARCH
(?<=PR1=)'(\d+)'
REPLACE
\1
Notes :
-
If necessary, check the Match case option, if the case pr=1 may happen !
-
Due to the look-behind feature
(?<=PR1=)
, you cannot use the Replace button, successively and must, exclusively, use the Replace All button !!
Cheers,
guy038
P.S. :
For newby people, about regular expressions concept and syntax, begin with that article, in N++ Wiki :
http://docs.notepad-plus-plus.org/index.php/Regular_Expressions
In addition, you’ll find good documentation, about the Boost C++ Regex library, v1.55.0 ( similar to the PERL Regular Common Expressions, v5.8 ), used by
Notepad++
, since its6.0
version, at the TWO addresses below :http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
http://www.boost.org/doc/libs/1_55_0/libs/regex/doc/html/boost_regex/format/boost_format_syntax.html
-
The FIRST link explains the syntax, of regular expressions, in the SEARCH part
-
The SECOND link explains the syntax, of regular expressions, in the REPLACEMENT part
You may, also, look for valuable informations, on the sites, below :
http://www.regular-expressions.info
http://perldoc.perl.org/perlre.html
Be aware that, as any documentation, it may contain some errors ! Anyway, if you detected one, that’s good news : you’re improving ;-))
-
-
Hello @guy038,
Thank you so much for taking your time and answering in this theme!
Could you also help with reverse replacement: adding quotation marks before and after numbers (it`s always 4 numbers in a row preceding by PR1=) like PR1=0066 or PR1=3601 or PR1=3722 -> PR1=‘0066’ or PR1=‘3601’ or PR1=‘3722’ -
I would do it like this:
Note: Before text:
PR1='0123' PR1=7777 PR1='0000' PR1=3456
Case 1: PR1=‘1234’ —> PR1=1234 (remove quotes):
Find-what zone:
(?-i)PR1='(\d{4})'
Replace-with zone:PR1=\1
After text:PR1=0123 PR1=7777 PR1=0000 PR1=3456
Case 2: PR1=1234 —> PR1=‘1234’ (add quotes):
Find-what zone:
(?-i)PR1=(\d{4})
Replace-with zone:PR1='\1'
After text:PR1='0123' PR1='7777' PR1='0000' PR1='3456'
Case 3: PR1=‘1234’ —> PR1=1234 & at same time PR1=4321 —> PR1=‘4321’ (add and remove quotes at same time):
Find-what zone:
(?-i)PR1=(')?(\d{4})(')?
Replace-with zone:PR1=(?1:')\2(?3:')
After text:PR1=0123 PR1='7777' PR1=0000 PR1='3456'
For any of these cases, you do not have to use the Replace All button, although you may. Find Next and Replace combinations to selectively replace is fine.
-
@Scott-Sumner that`s amazing. Thank you very much for your help!