Mobile app version of vmapp.org
Login or Join
Debbie163

: Indesign grep: Grab everything but I need to be able to grab the birth year in a summary of a number of people. I know how to grab exactly 4 digits and I know how escape any digit. But

@Debbie163

Posted in: #AdobeIndesign #Grep

I need to be able to grab the birth year in a summary of a number of people. I know how to grab exactly 4 digits and I know how escape any digit. But I cannot seem to be able to combine the two.

Here is my code for finding everything but digits [^[d{4}]. Unfortunately it omits all digits - not exclusively the ones with 4 digits.

Has any anyone got an idea?

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Debbie163

2 Comments

Sorted by latest first Latest Oldest Best

 

@Debbie163

Here is how I solved it.

First I moved back to my Google spreadsheet using Regex.

I did the thing in 2 steps which could probably be joined together.


I want to use the =REGEXREPLACE function that recognizes a certain string pattern. But as this function only accepts strings and not dates or numbers I add a character "A" to the dates in a new column (C) like so: =JOIN(""; B2 ;"A"). The first parameter is an empty divider that I have no use for.
I then run this code onto the new column: =REGEXREPLACE(C2; "d{2}Dd{2}D"; "") into a new column. Basically it finds the day+month parts by using the pattern of digit.digit.nondigit.digit.digit.nondigit (nondigit being the seperators "/" and the added charatcer "A"). All of this is then replaced with a empty string "" which leaves the remaining 4 digits.

10% popularity Vote Up Vote Down


 

@Kimberly620

There is no operator for not matching sequences in regular expressions (just items to match [^a] is translated to anything but a, [^ab] is anything but a or b not b a followed by b). It is still a matching statement

There is however a negative look ahead which says if this happens discard match. This however does not work in the general case only if its positional. To give a better answer you should post some examples of what your actually matching.

An alternate strategy might to match everything then discard the unwanted things. For example if you wanted to delete all except years in:

Benjamin 1996 Mark 1999 Mia 2005


And used find:

.*?(d{4})[^d]*


Replace:

Year: ~b


would result in:

Year: 1996
Year: 1999
Year: 2005


When replace all is chosen. If you want to do the reverse then just match for d{4} and replace with nothing...

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme