Skip to content
This repository has been archived by the owner on Aug 22, 2020. It is now read-only.

Capture Groups? #24

Closed
brookestewart opened this issue Sep 30, 2015 · 4 comments
Closed

Capture Groups? #24

brookestewart opened this issue Sep 30, 2015 · 4 comments

Comments

@brookestewart
Copy link
Collaborator

I'm trying to tag the title of the chapters in the Voyage narrative. I have \</l\>(\n^.*\n^.*) that selects the chapter name after the CHAP. which is tagged with <l></l> but when I try to replace the \</l\>(\n^.*\n^.*) with <l>\1</l> it says that it's a malformed expression and won't replace it.

@ebeshero
Copy link
Owner

@brookestewart Sorry I didn't see this until now, though I'm surprised I'm awake! Yes, when I try your expression for the "Find" window here, I see your expression works to match on the lines you want, but right, the Replace tells you the "match is not possible." There's a reason for this. The capturing group ( )'s don't let you include the caret or dollar sign that signal the literal start and end of a line. Your match works for me without the ^ symbols since you are already pulling up a \n character. The \n character is allowed inside a capturing group. So if I run \</l\>(\n.*\n.*) in the Find window, I'm able to insert the capturing group in my Replace with \1. Hope that helps!

@brookestewart
Copy link
Collaborator Author

That helped, but it won't insert the first <l> when I replace it, I don't know why. Also, I'm having trouble capturing dates within brackets that continue over a line. Nothing I try seems to work.

@ebeshero
Copy link
Owner

Hmm. I wonder if your first <l> Is actually there but it's not sitting exactly where you expect? I am not in front of a computer right now, so I can't test this, but my hunch is that the positioning of \n in the replace is causing your tags to be spread out.

@ebeshero
Copy link
Owner

As for dates, remember how you matched on quotations that spanned over multiple lines in the Blithedale Regex (Regex Exercise 2)? Matching on square brackets and their internal content is similar, but you have to escape the square bracket, which has a special meaning in Regex!

I did the dates in a couple of passes, because some of them are stacked together like so:
[...][...] . Oh--I remember you need to insert a literal space (pressing the space bar) in the replace window if you want to replace ][ with a white space.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants