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

Use GREP to remove plus symbols and brackets

Participant ,
Aug 03, 2023 Aug 03, 2023

Hi all!!

 

I have a document with lots of numbers in it. Some of the numbers are part of copy/paragraphs and some are in tables.

 

Some of the numbers within the copy have a + after them, and some of them have a + before them. I need to remove all the plus signs that come AFTER a number but not before, and obviously to leave the number (which is always different).

 

In the tables, some of the numbers have an x before them and the x and the number are in brackets. These bracketed numbers are always in a specific column, but not all the numbers in that column have the brackets. 

 

I need to remove all the brackets in this specific column, leaving all the numbers as they are (again, different numbers). There are however brackets in other columns of the tables which need to stay but do not have the x in them, just a number. 

 

I figured out I can use GREP to FIND all the plus signs after a number with \d\+, but I can't figure a way to remove the +, it just replaces the number with \d and removes the +.

 

Are either of these things possible or am I trying to push capabilities too far?
Thanks in advance for any help!

 

 

TOPICS
How to
1.5K
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 ,
Aug 03, 2023 Aug 03, 2023

One way to isolate the text in one column is to select the text in that column and assign a character style to it. That style can be nothing more than a style name with no attributes. That will allow you to specify the character style in your find formatting.

If I understand you correctly with the Plus sign problem there are at least two approaches that should work.

First is to find (\d)(\+) and replace with $1

Second would be to find (?<=\d)\+ and leave the change field blank

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
Participant ,
Aug 03, 2023 Aug 03, 2023

Thanks Peter! That was speedy ^_^

Unfortunately for the brackets, the table appears on about 150 pages across 3 or 4 documents, maybe more! So would be quicker to just remove them manually there I think.

Your first + sign solution is perfect though, thank you!!! Wasn't sure I understood the second one haha. I have a very limited knowledge of GREP, I'd really like to understand it better but a combination of not having the time and not having found anywhere that seems to explain what all the different stuff does rather than just provide examples of how to use different strings means it's a slow process!! 

This is extremely helpful though, and much appreciated being so fast to reply. Thank you!!!!


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 ,
Aug 03, 2023 Aug 03, 2023

Second GREP was a positive look-behind. It matches + sign if there is a digit preceding it. By changing to nothing that plus sign is removed.

You should be able to higlight all the text in a single row or column of any table with a single click. With the Text tool hover the cursor over the column until it becomes a balck arrow, then click.

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 ,
Aug 03, 2023 Aug 03, 2023

You were almost there you just need to look for the digit but don't include it - there's a few ways to do it

For the plus symbol

\d\K\+

this works like below except it's easier to remember
The \K escape sequence is used to reset the start of the reported match. In other words, it allows you to match a pattern but only report the text that comes after \K.

Another way to write it is 
(?<=\d)\+
This is negative lookbehind for a digit - but don't include and then just a + symbol

or you could have used 
(\d)\+
Replace with 
$1
When the \d is in a brackets it is found text
$1 would be first found
So it replaces it with the same character it finds
This is useful if you want to swap the digit and the plus - say if you had 2+ and it was supposed +2
You could find

(\d)(\+)
replace with
$2$1

and it would swap cos \d is 1 and \+ is 2

And this is useful for many scenarios not just swapping

 

========================

For the other one - can you show us an example?

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
Participant ,
Aug 03, 2023 Aug 03, 2023

Thanks Eugine! The "K" thing is really useful, thanks for explaining!

Look ahead and look behind are things I haven't managed to wrap my head around yet haha

So what exactly does the $ do/mean? That is really handy to know for swapping things around should I need to, thank you!

The brackets situation is as below, so the final column in the one I need to target, and I think the brackets, when they appear, are always in that final bottom right cell too. 

Isoneryum_0-1691077770690.png

 

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 ,
Aug 03, 2023 Aug 03, 2023

When you put things in partenthesis like finding a number

you find \d

to mark at is found you write it as (\d)

When you want to replace it you can put 

$1 

 

if you have two things like (\d)(\+)

$1 is \d and $2 is \+
so in the replace field you put

 

$2$1 

 

And that transposes them. 

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 ,
Aug 03, 2023 Aug 03, 2023

I don't think there's any way to target individual columns/rows

 

So it's removing the brackets around B (x2)?

This is where our $1 can come in handy

(\u.+)\((x\d+)\)
Replace with
$1$2

 

That is \u is uppercase

.+ is any character

(\u.+) putting them in brackets wraps it up as found text $1

 

\( is open brackets

 

(x\d+)
this the letter x followed by digit and more
- and the brackets wraps it up as found item $2

 

\) is the close bracket

 

Replace with $1 $2

Uses the found text to put back

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
Participant ,
Aug 04, 2023 Aug 04, 2023

Thank you both! Your solutions worked perfectly, I'm still not sure I understood what I did but when I'm not totally snowed under, I will definitely come back and try to figure it out for myself lol. Thank you!! 

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 ,
Aug 04, 2023 Aug 04, 2023
LATEST

Now that I'm thinking abouit it, if you've gone to the trouble of selecting the table column you need to target you don't actaully need to assign a character style (though that might be useful later if you need to do another find/change on that column) but you could simply set the scope of your find/change to selection.

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