thebourneid
thebourneid

Reputation: 67

Regular expression lowercase

I'm using this regex to lowercase prepositions, conjunctions, etc. in text files, and I want to add 2 exceptions: do not lowercase when $1 is preceded by ":" or preceded by "-". What is the proper, concise way to do that. Thanks.

s/(\s(?:a|about|an|and|at|by|for|from|in|is|it|of|on|the|to|with))\b/\L$1/gi;

Upvotes: 5

Views: 689

Answers (1)

sidyll
sidyll

Reputation: 59287

Add a negated look-behind before $1:

(?<![:-])

Upvotes: 3

Related Questions