Using wildcards in MS Word to replace special characters and reformat text - replace

I'm trying to work out how to replace the following sentence:
What’s Viktoria made / makes / making in the kitchen at the moment?
with this:
What’s Viktoria [**made**makes**making] in the kitchen at the moment?
using Find & Replace with wildcards in MS Word.
Unfortunately, I'm having trouble working out a way of doing this. I've made various attempts using things like (*)(\/)(*)(\/)(*) and ([! ]*\/*\/*[! ]) but I'm getting the entire string before; i.e. it highlights everything, not just made / makes / making. I guess there might be an easier way searching for the formatting (as the only part I want to target is in italics), but any way of doing it would be greatly appreciated!
Thanks in advance. Hopefully the explanation is clear enough!
Jamie

This may be what you're after. With wildcard searching on, for the search pattern use:
(<*>) [/] (<*>) [/] (<*>)
and for the replace pattern use:
[**\1**\2**\3]
If you want to remove the italics, choose italics font format for the search pattern and regular font format for the replace text.
Hope that helps.

Related

Search and replace with particular phrase

I need a help with mass search and replace using regex.
I have a longer strings where I need to look for any number and particular string - e.g. 321BS and I need to replace just the text string that I was looking for. So I need to look for BS in "gf test test2 321BS test" (the pattern is always the same just the position differs) and change just BS.
Can you please help me to find particular regex for this?
Update: I need t keep the number and change just the text string. I will be doing this notepad++. However I need a general funcion for this if possible. I am a rookie in regex. Moreover, is it possible to do it in Trados SDL Studio? Or how am i able to do it in excel file in bulk?
Thank you very much!
Your question is a bit vague, however, as I understand it you want to match any digits followed by BS, ie 123BS. You want to keep 123 but replace BS?
Regex: (\d+)BS matches 123BS
In notepad++ you can:
match (\d+)BS
replace \1NEWTEXT
This will replace 123BS with 123NEWTXT.
\1 will substitue the capture group (\d+). (which matches 1 or more digits.
You could do this in Trados Studio using an app. The SDLXLIFF Toolkit may be the most appropriate for you. The advantage over Notepad++ is that it's controlled and will only affect the translatable text and not anything that might break the integrity of the file if you make a mistake. You can also handle multiple files, or even multiple Trados Studio projects in one go.
The syntax would be very similar to the suggestion above... you would:
match (\d+)BS
replace $1NEWTEXT

REGEX in MS Word 2016: Exclude a simple String from Search

So I read a lot about Negation in Regex but can't solve my problem in MS Word 2016.
How do I exclude a String, Word, Number(s) from being found?
Example:
<[A-Z]{2}[A-Z0-9]{9;11}> to search a String like XY123BBT22223
But how to exclude for example a specefic one like SEDWS12WW04?
Well it depends on what you need to achieve or is this a matter of curiosity... RegEx is not the same as the built-in Advanced Find with Wildcards; for that you need VBA.
Depending on your need, without using VBA, you could make use of space and return characters - something like this will work for the strings provided: [ ^13][A-Z]{2}[0-9]{1,}[A-Z]{1,}[0-9]{1,}[ ^13] (assuming you use normal carriage returns and spaces in your document)
Anyway, this is a good article on wildcard searches in MS Word: https://wordmvp.com/FAQs/General/UsingWildcards.htm
EDIT:
In light of your further comments you will probably want to look at section 8 of the linked article which explains grouping. For my proposed search you can use this to your advantage by creating 3 groups in your 'find' and only modifying the middle group, if indeed you do intend to modify. Using groups the search would look something like:
([ ^13])([A-Z]{2}[0-9]{1,}[A-Z]{1,}[0-9]{1,})([ ^13])
and the replace might look like this:
\1 SOMETHING \3
Note also: compared to a RegEx solution my suggestion is kinda lame, mainly because compared to RegEx, MS-Words find and replace (good as it is, and really it is) is kinda lame... it's hacky but it might work for you (although you might need to do a few searches).
BUT... if it really is REGEX that you want, well you can get access to this via VBA: How to Use/Enable (RegExp object) Regular Expression using VBA (MACRO) in word
And... then you will be able to use proper RegEx for find and replace, well almost - I'm under the impression that the VBA RegEx still has some quirks...
As already noted by others, this is not possible in Microsoft Word's flavor of regular expressions.
Instead, you should use standard regular expressions. It is actually possible to use standard regular expressions in MS Word if you use a special tool that integrates into Microsoft Word called Multiple Find & Replace (see http://www.translatortools.net/products/transtoolsplus/word-multiplefindreplace). This tool opens as a pane to the right of the document window and works just like the Advanced Find & Replace dialog. However, in addition to Word's existing search functionality, it can use the standard regular expressions syntax to search and replace any text within a Word document.
In your particular case, I would use this:
\b[A-Z]{2}[A-Z0-9]{9,11}\b(?<!\bSEDWS12WW04)
To explain, this searches for a word boundary + ID + word boundary, and then it looks back to make sure that the preceding string does not match [word boundary + excluded ID]. In a similar vein, you can do something like
(?<!\bSEDWS12WW04|\bSEDWS12WW05|\bSEDWS12WW05)
to exlude several IDs.
Multiple Find & Replace is quite powerful: you can add any number of expressions (either using regular expressions or using Word's standard search syntax) to a list and then search the document for all of them, replace everything, display all matches in a list and replace only specific matches, and a few more things.
I created this tool for translators and editors, but it is great for any advanced search/replace operations in Word, and I am sure you will find it very useful.
Best regards, Stanislav

How to match and replace n number of times with RegEx

I'm using TextWrangler, the free version of BBEdit on the Mac, which I understand uses the PCRE engine.
What I want to do is match a specific number of lines and replace as well.
After a lot of searching I came up with this:
(^(.*\r)){25}
This lets me match up to 25 lines. It works great, but the problem comes when I want to actually replace something. I can't figure out how to do it.
For example, I would like to replace all of the returns "\r" with tabs "\t".
Hopefully this is actually possible. I'd appreciate any help. Thanks!
Regexp domain is searching. You cannot replace using regexp; a programming language or editor can use regexp as the search part of its search-and-replace function. Thus, the way to do 25 replacements is purely in the domain of said programming language or editor. If it does not provide such capability, either directly in search-and-replace or as a macro/loop/other, then you cannot do it automatically.

Regex to match surrounding text

I need to replace "something[anything]" with "somethingElse(anything)", the tricky part is anything could be anything, and I don't want to replace that. Is it possible to do with regex?
P.S. In real scenario I'd be using PHPStorm to look / replace it. It would help me a lot to show me what to put exactly at the find window.
Thank you!
Idea: Capture 'anything' in a capturing group in regex. Then, back reference it in the replacement.
For example: search for something[([^]]*)\] and replace with somethingElse($1).

RegEx Search & Replace (via Dreamweaver CS5)

I have to deal with a problem and maybe you can help.
I took over a Website with a lot of code and would like to have it run on PHP 5.4.
But there are a LOT of statement's like this:
if($arrayname['keyname']>"") ....
I would like to replace them all with:
if(!empty($arrayname['keyname'])) ....
Doing it manually will take forever :-(
Do you know how to use Dreamweaver's CS5 search & replace with RegEx capabilites - unfortunately my RegEx knwoledge is limited.
Of course the regex must be "variable, as the arrayname and the keyname always changes.
Any help on finding the correct RegEx Stamtent is HIGHLY appreciated .
Regex to find all occurrences of if($arrayname['keyname']>""), whatever arrayname and keyname are, if only letters :
if\\(\\$[a-zA-Z]*\\[\'[a-zA-Z]*\'\\]>\"\"\\)
You'll have to find how to use BackReferences in Dreamweaver. If it uses standard Regex, then use the tutorial in the link, it will be of great help for you.
To complete and close this question:
In Dreamweaver search for (Regex Search in Code):
if\(\$(\w+)\[['"](\w+)['"]\]>""\)
Replace by:
if(!empty($$1['$2']))