3

I need to clean up some tables in Word, where semicolons and text after them is redundant, e.g.

text1 ; text 2

where above is a content of one cell and I need to remove semicolon and everything after it until end of cell; unfortunately text 2 doesn't have any specific pattern.

I try to do that with Word's built-in find and replace using regex.

As the desired end of my regular expression is the end of the cell, I can't match it, I've tried several combinations of any character ;?* ;* ;?@ but all stops at the shortest matching text, is there a way to make it match until end of cell?

6
  • Oops. Was looking at wrong link.
    – DavidPostill
    Oct 30, 2015 at 12:17
  • Does ;?{1,} work?
    – DavidPostill
    Oct 30, 2015 at 12:22
  • yes, it "works", matches ; and one character after it Oct 30, 2015 at 12:24
  • Then something like ;?{1,9999} should work? "{n,m} matches from n to m occurrences of the previous character or expression"
    – DavidPostill
    Oct 30, 2015 at 12:28
  • Please try ;[ 0-9A-Za-z]*
    – DavidPostill
    Oct 30, 2015 at 13:27

4 Answers 4

6

This seems to be working:

;[!¤]{1,}

I used generic currency sign ¤, you may use any other symbol you are sure is not included in text following semicolon (maybe it's semicolon itself).

Just a note: leaving curly brackets' second bound empty does not mean an endless string, I found out by trial that the extent is limited to 255 chars.

1
  • Thanks! that really works! Replacing {1,} to @ or * makes a lazy match, as well as replacing [!#] to ?. So I can't find any logic behind, but it works:) Nov 4, 2015 at 5:46
2

I need to remove semicolon and everything after it

Use the following regular expression:

;?{1,9999}^13
  • {n,m} matches from n to m occurrences of the previous character or expression
  • ^13 matches a paragraph break

Source Find and replace text by using regular expressions (Advanced)

6
  • Thanks for your effort! Yes, this works for normal paragraphs, but table cells doesn't end in a paragraph mark, therefore ^13 doesn't match end of cell Oct 30, 2015 at 12:57
  • Does it work if you remove the ^13 or does it continue matching into the next cell?
    – DavidPostill
    Oct 30, 2015 at 12:58
  • ;?{x,9999} matches only the semicolon and the following x characters Oct 30, 2015 at 12:59
  • Try using a smaller number than 9999 maybe ;?{x,99} or something
    – DavidPostill
    Oct 30, 2015 at 13:00
  • all the same, also {1,} matches only one character Oct 30, 2015 at 13:02
0

Copy your table somewhere else; convert it to text (Layout / Convert to text) and pick Paragraph delimiter.

Proceed replacing ;*^13 with ^9, having Use wildcards checked. Cut this block of text.

Select all text on the original table and "text-only" paste.

2
  • Unfortunately there are also different formatting and comments, this solution doesn't preserve them. Oct 30, 2015 at 17:59
  • This workaround aims to preserve table formatting, you need to paste text without its formatting (you should see that as an option when you right click - hovering shows you a preview), and it is going to get original tables'. Don't know about comments, sorry.
    – SΛLVΘ
    Oct 30, 2015 at 18:18
-1

Best way to deal with this would be to copy/paste you entire table into Notepad++ (or any proper text editor with regex support), do your edits then.

4
  • Hi Fritz! Welcome to SU. I would be much more helpful if you provide more details on how the problem can be solved. For instance, you could probem a regex that can match the pattern OP is trying to remove and tell her/him how it can be removed in Notepad++.
    – Isaac
    Dec 14, 2019 at 5:19
  • 1
    Copying to notepad would lose formatting. I wouldn't be able to copy it back to Word Dec 14, 2019 at 6:52
  • @MátéJuhász : no it wouldn't. Copying back onto the original text, then carefully selecting the right paste options (e.g "text only") will apply the current formatting from your Word section to the pasted text, therefore restoring it. Dec 16, 2019 at 12:12
  • @Isaac : thanks for the advice, I think having actually gotten down to the bottom of my proposition, which does not rely on any particular regex, for that matter. Anyway : (1) Copy entire section (i.e. table) (2) Paste table to Notepad++ (or other editor) (3) Check EOL symbol is CR/LF, changing if necessary (4) Find/replace following regex pattern : ;[^\n]+ with " " (empty string) (5) Paste back into Word, onto originally selected text. Right after, select "text only" among paste options proposed by Word, to let it apply formatting to the pasted text – Dec 16, 2019 at 12:13

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .