Replace last word with asterisk, or last two words

when using find and replace which can be used as a wildcard for a string of characters
find and replace tricks
find and replace list of words
word find and replace exclude
word replace everything between
microsoft word find asterisk
find and replace wildcard excel
word match prefix

I need to hide surname of persons. For persons with three words in their name, just hide last word, ej:

Laura Torres Bermudez

shoud be

Laura Torres ********

and for

Maria Fernanda Gonzales Lopez

should be

Maria Fernanda ******** *****

I think they are two regex because based on the number of words, regex will be applied.

I know \w+ replaces all word by a single asterisk, and with (?!\s). I can replace chars except spaces. I hope you can help me. Thanks.

This is my example: https://regex101.com/r/yW4aZ3/942

Word: Find and replace multiple asterisks used as separator lines , This string defines the third and last section of the Find. \1 replaces the first part of the wildcard string with itself. In other words, the paragraph  The idea is to first split given sentence into different words. Then traverse the word list. For every word in the word list, check if it matches with given word. If yes, then replace the word with stars in the list. Finally merge the words of list and print.

Finding and replacing characters using wildcards, is used to find one or more occurrences of the previous character. For example, lo@t At its simplest, we have here two words – John and Smith. They can be  Is there a way to set regex to ignore a set of words separated by space? I have different products names like: "Matrix 10X, 10 ml + DISPENSER" "Matrix 10X,10ml + DISPENSER" wher

Interested if this can be done in JavaScript without a callback, I came up with

str = str.replace(/^(\w+\W+\w+\W+\b)\w?|(?!^)(\W*)\w/gy, '$1$2*');

See this demo at regex101

The idea might look a bit confusing but it seems to work fine. It should fail on one or two words but start as soon, as there appears a word character after the first two words. Important to use the sticky flag y which is similar to the \G anchor (continue on last match) but always is bound to start.

To not add an additional asterisk, the ...\b)\w?... part after the first two words is essential. The word boundary will force a third word to start but the first capturing group is closed after \b and the first character of the third word will be consumed but not captured to correctly match the asterisk count.

The second capturing group on the right side of the alternation will capture any optional non word characters appearing between any words after the third one.

var strs = ['Foo', 'Foo Bar B', 'Laura Torres Bermudez', 'Maria Fernanda Gonzales Lopez'];
strs = strs.map(str => str.replace(/^(\w+\W+\w+\W+\b)\w?|(?!^)(\W*)\w/gy, '$1$2*'));
console.log(strs);

Program to replace a word with asterisks in a sentence , Python | Replace rear word in String · Python program to read file word by word · Python program to count words in a sentence · Java program to swap first and last  So I have big notepad file with hundreds of lines, with different last words in each line. I don't need them and want to delete them, but I'm not sure what to find in Mark or Replace. The words consist of numbers, letters, special characters. I want to remove all of that from the last word in every line.

Java program to swap first and last characters of words in a sentence, Write a Java Program to Swap first and last character of words in a Sentence as Approach:As mentioned in the example we have to replace first and last character of word and keep rest of the alphabets as it is. between two words. length of the longest word in a sentence · Program to replace a word with asterisks in a  The second last word (the nth word where n = the number of words -1): regexp_substr(text, '\S+', 1, regexp_count(text,'\S+') -1) If you are processing a significant number of rows then the regex functions can be slow.

Object-Oriented Programming Using C++, Include data fields to hold the Employee's ID number, first name, last name, and to choose whether to search for an Employee by (1) ID number, (2) last name, Allow the user to guess letters to replace the asterisks in the hidden word until​  I want to remove the last word OR even there can have a space after OR or sometimes it can't. Please keep in mind that sometimes the last word can be "OR" and sometimes it can be "AND". So please give a solution how can I remove last word ? I am triying through this code. By using following code I can get last word. But I don

Replace using wildcards, Insert your find and replace strings using the following guide for inspiration. Wildcard, Description, Notes ? and *, The two most basic wildcards are ? and *. Word does not limit the number of characters that the asterisk can match, and it does not require that is used to find re-occurrences of the previous character (if any). The length of these asterisk ‘lines’ weren’t the same—sometimes the author had used 3 asterisks, other times they’d used 4 or 8 or 35 or some other random number of asterisks. How to get rid of them all at once? Enter Word’s wildcard find and replace feature! Press Ctrl+H to open the Find and Replace dialog box.

Comments
  • What is your regex platform?
  • What is the programming language? JS (this option is used in the demo)? In JS, use s.replace(/^(\S+\s+\S+)([\s\S]*)/, function($0, $1, $2) {return $1 + $2.replace(/\S/g, '*');})
  • Iam using java or javascript for the example, I am working in this snipped regex101.com/r/yW4aZ3/942
  • can you help me to translate this to java regex? I am getting an error about the first plus, it says " + repetition not allowed inside lookbehind" and causes PatternSyntaxException
  • @wilmerlpr See my answer. Quite few JS environments support an infinite width lookbehind for the time being.
  • Oh, I'm afraid it won't work on Java regex engine :( some regex engines does not support quantifiers in lookbehind. Without that, you'll probably have to use other way than a plain regexp replace.