thisiscrazy4
thisiscrazy4

Reputation: 1965

How to escape single quote in a string using .match method in ruby

My code is this:

description = contents.match(/===========(.*?)What's New in this Version/m)[1].strip

The code runs fine but now everything after the single quote is in blue and I need a single quote to end it. But where would I put it or how would I escape it? I tried putting a backslash before the single quote but that doesn't change anything.

Upvotes: 1

Views: 1095

Answers (3)

Lars Haugseth
Lars Haugseth

Reputation: 14881

To work around the shortcomings of the Xcode syntax highlighter, you can replace the single quote with the octal escape code for that character:

/===========(.*?)What\047s New in this Version/m

PS. You can also shorten the start of your regex a bit:

/={11}(.*?)What\047s New in this Version/m

Upvotes: 1

Casper
Casper

Reputation: 34308

It seems to be an XCode bug. You can try and get around it with this:

/===========(.*?)What.s New in this Version/m
# fix here ----------^ 

Upvotes: 0

ennuikiller
ennuikiller

Reputation: 46965

You typically use the backslash "\" to escape special characters:

/===========(.*?)What\'s New in this Version/m

Upvotes: 0

Related Questions