Hi Jean,,

Thank you for the detailed explanation! This seems to find every 
three-number permutation wrapped in *<loc>* or *<loc2>*, but I'm looking to 
remove two-number permutations. I figured out that moving the second + 
symbol does the trick.

Thanks again!



On Saturday, May 22, 2021 at 10:42:18 AM UTC-7 jj wrote:

> Hi Ron,
>
> Here is a regular expression that should match your pattern:
>
> <(loc2?)>[1-5](?:\.\d+)+</\1>
>
> The same but commented:
>
> (?x)                (?# allow comments and whitespace)
> <                   (?# start of opening tag)
> (                   (?# start of capturing parenthesis)
>     loc             (?# loc )
>     2?              (?# optional 2 )
> )                   (?# end of capturing parenthesis. Will match and store 
> 'loc' or 'loc2' in capture \1)
> >                   (?# end of opening tag)
> [1-5]               (?# one digit in the range 1..5)
> (?:                 (?# start of non-capturing parenthesis)
>     \.              (?# a dot. It has to be escaped otherwise it will be 
> considered a one character wildcard.)
>     \d+             (?# one or more digits)
> )                   (?# end of non-capturing parenthesis)
> +                   (?# one or more occurrence of the non-capturing 
> parenthesis)
> </                  (?# start of closing tag)
> \1                  (?# captured value of first capturing parenthesis)
> >                   (?# end of closing tag)
>
> The BBEdit Help has a very good Grep Reference:
>
> menu Help > Quick Reference > Grep Reference
>
> HTH,
>
> Jean Jourdain
>
> On Saturday, May 22, 2021 at 6:39:51 PM UTC+2 severdia wrote:
>
>> Hi,
>>
>> I can't seem to figure out a way to find and replace some numbers using 
>> Grep. This is what I have.
>>
>> *<loc>2.2</loc><loc2>2.2.93</loc2>*
>>
>> I have many cases where there are 3 numbers separated by two periods 
>> wrapped in *<loc>* (like this: *<loc>2.2.309</loc>*) as well as the 
>> example above with 2 numbers separated by 1 period wrapped in* <loc>*. I 
>> want to find where there are only two numbers and delete that *<loc>* 
>> element. For example I tried:
>>
>> *<loc>[0-9]\.[0-9]</loc><loc2>[0-9]\.[0-9]\.[0-9]</loc2>*
>>
>> But that seems to only only single digits and I can't replace values. 
>> Example values in *<loc>* are:
>>
>> *<loc>1.13.333</loc>*
>> *<loc>5.3.28</loc>*
>> *etc.*
>>
>> The first number will be in the range of 1-5, the second will be 1-50, 
>> and the third will be 1-2300 (those ranges aren't as important, just for 
>> the number of digits to factor in). I imagine I could do all permutations 
>> of what I have above with single digits, but it seems there's surely a 
>> better way to find the <loc> elements containing only two numbers vs. three.
>>
>> Any guidance would be appreciated! Maybe the Bbedit shortcut menu for 
>> grep characters could add something like this? 
>>
>> Thanks!
>>
>> Ron
>>
>>
>>
>>

-- 
This is the BBEdit Talk public discussion group. If you have a feature request 
or need technical support, please email "[email protected]" rather than 
posting here. Follow @bbedit on Twitter: <https://twitter.com/bbedit>
--- 
You received this message because you are subscribed to the Google Groups 
"BBEdit Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/bbedit/56cfcac5-8b60-435d-bc2f-e9ebd0c4719an%40googlegroups.com.

Reply via email to