4 Replies - 1935 Views - Last Post: 20 January 2016 - 02:40 PM

#1 atraub   User is offline

  • Pythoneer
  • member icon

Reputation: 828
  • View blog
  • Posts: 2,236
  • Joined: 23-December 08

Match on new line characters not preceeded by a double quote

Posted 20 January 2016 - 01:19 PM

I've been working on coming up with a regex to match on all new lines that aren't preceeded immediately by a ". I found this [^\"]\n and it almost works, the only problem is it matches on both the new line and the previous character, which isn't what I want. Anyone know how to fix it?



(The fact that this is the first post in this forum in over almost 6 years doesn't concern me at all...)

Is This A Good Question/Topic? 0
  • +

Replies To: Match on new line characters not preceeded by a double quote

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14146
  • View blog
  • Posts: 56,699
  • Joined: 12-June 08

Re: Match on new line characters not preceeded by a double quote

Posted 20 January 2016 - 01:21 PM

Ah.. you posted this in the 'snippet' section.

(n0000000000000b) ; )

I'll move it to 'software dev'.
Was This Post Helpful? 1
  • +
  • -

#3 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6561
  • View blog
  • Posts: 26,600
  • Joined: 12-December 12

Re: Match on new line characters not preceeded by a double quote

Posted 20 January 2016 - 01:36 PM

What are you trying to capture, the newline character? You need to capture it using parentheses (\n), creating a capture group.

Depending on the regex flavour (the language) you could use a negative lookbehind assertion with (?<!\")(\n), which captures newlines that aren't preceded by a quote.
Was This Post Helpful? 2
  • +
  • -

#4 atraub   User is offline

  • Pythoneer
  • member icon

Reputation: 828
  • View blog
  • Posts: 2,236
  • Joined: 23-December 08

Re: Match on new line characters not preceeded by a double quote

Posted 20 January 2016 - 02:30 PM

Firstly, I'm humiliated I made that mistake haha. I did a ctrl+F regex on the home page and didn't realize my mistake.

Secondly,yes, I'm attempting to only capture the new line character.

Thirdly, I'm just working on a python script, so I think look behinds are supported, but I should do some googles to check that.

Thank you friends!
Was This Post Helpful? 0
  • +
  • -

#5 andrewsw   User is online

  • RequestedRangeNotSatisfiable
  • member icon

Reputation: 6561
  • View blog
  • Posts: 26,600
  • Joined: 12-December 12

Re: Match on new line characters not preceeded by a double quote

Posted 20 January 2016 - 02:40 PM

JFYI If the language is specific then regex questions can be posted in the language's forum (Python).

(As I recall, I think it was discussed a little while ago that we wouldn't have a separate forum for regex, as the questions aren't that frequent and usually language-specific.)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1