- AuthorPosts
- September 5, 2010 at 5:02 am #8922
hydra
Memberi have a string that contains 3 characters that vary, it looks like this: board=XYZ
note: sometimes X=Y, or Y=Z (they can be either a letter or a number). thus, sometimes the string will read like this: board=K66.
what i want to do, is to find every instance where the variable pattern looks like “XYY” and switch the order to be “YYX”. can emeditor do this using the regular expression function? or can it only be done via script/macro?
September 5, 2010 at 5:28 am #8923Yutaka Emura
KeymasterHello hydra,
In the Replace dialog box, you can use replace
=(w)(ww)
with
=21
and check Use Regular Expressions.
Please let me know if you have further questions.
Thank you!September 5, 2010 at 5:51 am #8924hydra
Memberhi yutaka,
thx for the quick reply, however it doesnt do what i need it to do. allow me to explain:
1. when the pattern “board=XYY” is found, i need it to be changed to “board=YYX”. your above suggestion does this. so far so good.
2. BUT, when the pattern XXY is found, i want it to do nothing! your above suggestion changes all instances of XXY into XYX. this is something i must avoid.
is there any expression that can do both #1 while avoiding #2?
September 5, 2010 at 6:00 am #8925hydra
Memberif the regular expression function cant do this, can u write a simple script/macro that does this for me?
September 5, 2010 at 6:49 am #8926Jibz
MemberTry searching for
=(w)((w)3)
and replace with
=21
September 5, 2010 at 7:02 am #8927hydra
Memberjibz,
such an elegant solution! thank u so much!
September 5, 2010 at 6:54 pm #8928Yutaka Emura
KeymasterThat’s an excellent solution. Thnaks jibz!
September 6, 2010 at 5:20 am #8929Jibz
MemberGlad to hear it worked :-).
- AuthorPosts
- You must be logged in to reply to this topic.