Sublime Forum

Using regex in sublime text

#1

Ok after looking at this book and then this web page I figured I would try and dabble in the world of regex using python since I believe it comes bundled with Sublime.

However my question is where in Sublime text would I begin typing the expression to evaluate the text that i am trying to manipulate with regex?

0 Likes

#2

nevermind I found the little button that I am supposed to push. :blush:

0 Likes

#3

If you’re jumping into regex, I’d suggest getting the RegExr AIR app.
gskinner.com/blog/archives/2 … sktop.html

Great application to learn and test with. Community samples along with notes and a really simple test environment.

0 Likes

#4

Thanks for the suggestion now I can really practice exercises with confidence. Ok I am trying to test regex but it is not doing as as expected. It is supposed to check to see if the first letter of a sentence is capitalized and if it is not then capitalize it. But this is not working in the find dialog.

Get the first letter of the line and the first letter fallowing a ? . ! or \s(.?\s!]\s\w)|^(\b\w)

Pattern: /(.?\s!]\s\w)|^(\b\w)/g
Replace: $&

This is the regex:
RegExp: /(.?\s!]\s\w)|^(\b\w)/g
pattern: (.?\s!]\s\w)|^(\b\w)
flags: g
2 capturing groups:
group 1: (.?\s!]\s\w)
group 2: (\b\w)

0 Likes

#5

Try something like this:
find: “\b(\w)(.*.)” ==> word boundary, word character, bunch of characters, period
replace: “\u$1$2” ==> uppercase the word character, add the rest as is

You also have Edit -> Change case -> Title case (source is in Packages/Default/Transform.py). You could create a “Sentence case” or something.

0 Likes

#6

i have defined a following regex to replace \sid#(\d+)\s with <a href="/foo/bar?ID=$1">sp#$1</a>

suddenly what i get is a <a href="/foo/bar?ID=9999">sp#9999</a> where 9999 seems to be a last occurence of $1. Is my regex wrong or rather is it a bug?
EDIT. “reverse direction” was on

0 Likes