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?

  • Oops. Was looking at wrong link. – DavidPostill Oct 30 '15 at 12:17
  • Does ;?{1,} work? – DavidPostill Oct 30 '15 at 12:22
  • yes, it "works", matches ; and one character after it – Máté Juhász Oct 30 '15 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 '15 at 12:28
  • Please try ;[ 0-9A-Za-z]* – DavidPostill Oct 30 '15 at 13:27
4

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.

| improve this answer | |
  • 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:) – Máté Juhász Nov 4 '15 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)

| improve this answer | |
  • 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 – Máté Juhász Oct 30 '15 at 12:57
  • Does it work if you remove the ^13 or does it continue matching into the next cell? – DavidPostill Oct 30 '15 at 12:58
  • ;?{x,9999} matches only the semicolon and the following x characters – Máté Juhász Oct 30 '15 at 12:59
  • Try using a smaller number than 9999 maybe ;?{x,99} or something – DavidPostill Oct 30 '15 at 13:00
  • all the same, also {1,} matches only one character – Máté Juhász Oct 30 '15 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.

| improve this answer | |
  • Unfortunately there are also different formatting and comments, this solution doesn't preserve them. – Máté Juhász Oct 30 '15 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 '15 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.

| improve this answer | |
  • 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 '19 at 5:19
  • 1
    Copying to notepad would lose formatting. I wouldn't be able to copy it back to Word – Máté Juhász Dec 14 '19 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. – Fritz Wastika Dec 16 '19 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 – – Fritz Wastika Dec 16 '19 at 12:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.