regex - search and replace - "remember"?
-
I don’t know where in the document mentions where you can take what ever it has been found, and copies text and is pasted in the “replace with”. For example:
abcd/1234/efgh ijkl/5678/mnopbecomes:
abcd/efgh/1234 ijkl/mnop/5678(it’s swapped, by being replaced with [abcd/<memory 2>/<memory 1>]).
-
Open the Replace dialog by pressing Ctrl+h and then set up the following search parameters:
Find what box:
(?-s)(.{4})/(.{4})$
Replace with box:\2/\1
Search mode radiobutton: Regular expression
Wrap around checkbox: ticked
. matches newline checkbox: doesn’t matter (because the(?-s)leading off the Find what box contains ansvariant)Then press the Replace All button
-
Hmm … question is quite similar to this one, strange.
-
@Alan-Kilborn So, it’s something to do with a backreference. Is this caused by the parenthesis? Because the
.means to match any character and{ℕ}is the number of characters. Also, do backreferences’s numbering:-Starts at 0?
-Is numbered from left to right (example, the first parenthesis group is numbered 0 and the last is numbered 2)? -
@Adam-Yik said in regex - search and replace - "remember"?:
Is this caused by the parenthesis?
Yes.
do backreferences’s numbering: Starts at 0?
No, they start at 1, and they aren’t called backreferences, they’re called “capture groups”.
A pseudo-group #0 is for the overall match and is accessed at replace time as
$0rather than\0.Is numbered from left to right
Yes.
he first parenthesis group is numbered 0 and the last is numbered 2)?
No, but close. The first is numbered 1 and the second/last is 2.
-
@Alan-Kilborn thanks! sadly, up to 9 can be remembered within parent group at a time. But I think you can get around this by doing this multiple times.
-
@Alan-Kilborn To fully understand the subgroup, it is very similar to Directory-based system such as windows 10. However, up to 9 files and folders can exist in a directory, and to refer them on a path, you place each digit and without the path separator
/ -
@Adam-Yik said in regex - search and replace - "remember"?:
thanks! sadly, up to 9 can be remembered within parent group at a time
Actually, there is no such limitation. The substitutions section of the official docs says,
$ℕ,${ℕ},\ℕ⇒ Returns what matched the ℕth subexpression, where ℕ is a positive integer (1 or larger).By using the
${ℕ}notation, you can reference any capture group, not just the first 9. So the fifteenth group would be${15}in the replacement expression. -
@Adam-Yik said in regex - search and replace - "remember"?:
it is very similar to Directory-based system such as windows 10. However, up to 9 files and folders can exist in a directory, and
There is no such limitation in Windows, and it doesn’t have anything to do with regular expression processing. Please don’t spread misinformation.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login