Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

exact regex match for multiple equal signs

Tags:

regex

I am searching though a report that gets automatically generated. There are many sections and each section is separated by multiple "="(equal signs). I am wanting to create a simple script to basically extract certain data at a specific section. The only real determination of what section is what is based on the amount of equal signs.

How would I find only the "==" and not anything else?

====
===
==
=

I have used some light regex before and based on my very limited knowledge, I could do this for normal characters, such as \ba{2}\b however, trying to do this with \b={2}\b it does not work.

By doing the search as ={2} I am able to locate any and all of the double equal signs.

What am I missing here? I am not able to find much on this type of problem I am running into.

like image 287
TheChefSLC Avatar asked May 08 '14 03:05

TheChefSLC


1 Answers

This simple regexp match only ==

(?<!=)==(?!=)

Negative lookbehind check there's no = before. Negative lookahead checks there's no = after.

Regular expression visualization

like image 199
Hans Schindler Avatar answered Oct 21 '22 05:10

Hans Schindler