Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

GREP to find words before or after > symbol

Engaged ,
Jan 16, 2017 Jan 16, 2017

Hi guys,

I wonder if you can give me a little push in the right direction with this GREP code.

I want to find words which come before/after a space and a greater than symbol.

(?<=\s>)?\w+(?=\s>)

This is what I have but it doesn't find words which come after the symbol.

Menu > Menu > Menu

Would only find the first 2 Menus.

Thanks everyone

TOPICS
Scripting
14.9K
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Guide , Jan 16, 2017 Jan 16, 2017

Hi Jakec,

Basically a GREP like

\w([^\r>]+\w)*

would do a very good job (including when the menu item contains inner space), since it captures every string that starts and ends with a word character while not containing any >.

Now, what you want is to make sure that the pattern above is either preceded by >\s, or followed by \s>, in order to exclude lines that do not contain the X > Y > … > Z structure at all. So in fact you have an alternation of two distinct regex, first based on a lookbehind, sec

...
Translate
Community Beginner ,
Mar 27, 2017 Mar 27, 2017

Thank you obi-wan kenobi. You were my only hope.

Sent from my iPhone

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 08, 2018 Mar 08, 2018

Hi,

Made an adjustment to our headers and now my GREP isn't working.  Tried to adjust to no avail.  Help again is greatly appreciated. This is the grep for the BEFORE scenario: (Article|Section)\h\d+(\.[A-Z])?\h\K[^/\r]+(?=\h\h//|$).  How do I adjust this to work for the removal of the "2." from the format of our header, per the AFTER scenario shown below?  Thank you so much!

BEFORE:

Article 2 District Standards  //  Section 2.A General District Standards

AFTER:

Article 2 District Standards  //  Section A General District Standards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Mar 08, 2018 Mar 08, 2018

Try this:

(Article|Section)\h(\d+\.)?[A-Z])?\h\K[^/\r]+(?=\h\h//|$)

In other words, make the number before the letter optional.

P.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 08, 2018 Mar 08, 2018

Hmmm..  That unbolded everything. 

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 09, 2018 Mar 09, 2018

I'm trying to find a GREP that will work for this scenario, where there will always be "Article" followed by a number, then "Section followed by a letter.  Help is greatly appreciated!

Article 2 District Standards  //  Section A General District Standards

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Guide ,
Mar 10, 2018 Mar 10, 2018

Peter Kahrel's code could be corrected to make it work as:

(Article|Section)\h(\d+)?[A-Z]?\h\K[^/\r]+(?=\h\h//|$)

or

(Article|Section)\h(\d+|[A-Z])\h\K[^/\r]+(?=\h\h//|$)

… more locked:

(Article\h\d+|Section\h[A-Z])\h\K[^/\r]+(?=\h\h//|$)

Best,

Michel, from FRIdNGE

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Mar 12, 2018 Mar 12, 2018
LATEST

Perfect, thanks!

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines