Sublime Forum

Regex question

#1

How would I match one or more capitalized words?

<p class="extract">PLAN VIEW Blueprint drawn from a viewpoint directly above.</p>

I wand to replace with

<p class="extract"><strong>PLAN VIEW</strong> Blueprint drawn from a viewpoint directly above.</p>

I have tried many things, including the following, but only get one of the capitalized words or the entire line.

<p class="extract">([A-Z]+)(?:(\s+?)|\b) (partial search term, leaving off the rest of line for now)

0 Likes

#2

Looks like it works, but matches each individually, not the whole.

Best I was able to come up with quickly is

# The + after the first match makes it greedy, so it keeps going. ([A-Z]+\s)+\b

But that includes the final space. Shouldn’t matter for wrapping in tags, but it’s not as tidy. Making the \s be optional made it go back to the lazy match, though this wasn’t with the Sublime regex engine, so YMMV.

0 Likes

#3

How about

([A-Z]{2,}(?: [A-Z]+(?![a-z]))*)

Limitation is that the first capitalized word has to have at least two letters…

0 Likes

#4
([A-Z]+)(((\s+)([A-Z]+)\b)+|\b)

But I’m not a RE guru…

0 Likes

#5

Something like this?

(\b([A-Z]+\s*)+[A-Z]\b)

regexr.com?30dkv

0 Likes

#6

[quote=“nick.”]Something like this?

(\b([A-Z]+\s*)+[A-Z]\b)

regexr.com?30dkv[/quote]

You win…
And I like your url point to gskinner.com :smiley:
Maybe a relative of Jon ?

0 Likes

#7

How get first letter in string?

Try use ${1/(\w)(\w+)/\L\1/g}

But get small error…

0 Likes