IcedDante
IcedDante

Reputation: 6792

Sublime Bug with Regular Expressions

I'm trying to do a sublime regex search and replace with a backreference. Here's my data set:

if(requestType.endsWith("CompleteMulti")) {
if(requestType.endsWith("CompletePartial")) {
if(requestType.endsWith("Unfulfillable")) {

When I run the regular expression:

^.+"(\w+)".+$

with replace statement:

$1

I get the following output:

completemuLti
completepaRtial
unfulfillaBle

As you can see the case of the letters goes all screwy. I'm using Version 2.0.2, Build 2221

Is this a known issue? Some google searching has not turned up any data. If anyone knows a workaround for it please let me know.

Upvotes: 4

Views: 145

Answers (1)

msturdy
msturdy

Reputation: 10794

Before performing your "replace all", deselect the option "preserve case" (ALT+A)

"Preserve case" will preserve the case of the character that was in that position before. A quick demonstration:

if(requestType.endsWith("CompleteMulti")) {
if(requestType.endsWith("CompletePartial")) {
if(requestType.endsWith("Unfulfillable")) {
completemuLti
completepaRtial
unfulfillaBle

          ^ only this character is left in upper case

Another example. This time we will replace "sublime" with "bananas", using case-insensitive regex and with "preserve case" selected:

Before:

SUblime
suBLime
sublIME

After:

BAnanas
baNAnas
banaNAS

In response to IcedDante's comment, I can think of a use case where it would be the desired behaviour (contrived though it may be).. imagine a letter that you are sending out to a number of universities:

Dear University of Blahtown,

I am writing to enquire about your Applied Biology 101 course, as I understand you're the leading school in the field of biology. I have always had a keen interest in the field of biological reseach and so this course, Applied Biology 101, is of particular interest.

and then you want to also enquire about a geography course, you could find/replace "biolog" with "geograph", maintaining the case:

Dear University of Blahtown,

I am writing to enquire about your Applied Geography 101 course, as I understand you're the leading school in the field of geography. I have always had a keen interest in the field of geographical reseach and so this course, Applied Geography 101, is of particular interest.

Pretty contrived, I know.

note - I've tried looking for references to this in the documentation, but I can't find anything definite...

Upvotes: 4

Related Questions