Using regular expressions to do mass replace in Notepad++ and Vim
Solution 1
Everything before the A, B, C, etc.
That seems so simple I must be misinterpreting you. It's just
:%s/<.*>//
Solution 2
In Notepad++ you don't need to use Regular Expressions for this.
Hold down alt to allow you to select a rectangle of text across multiple rows at once. Select the chunk you want to be rid of, and press delete.
Solution 3
There is a very simple solution to this unless I have not understood the problem. The following regular expression:
(.*)(>)(.*)
will match the pattern specified in your post.
So, in notepad++ you find (.*)(>)(.*)
and replace it with \3
.
The regular expressions are basically greedy in the sense that if you specify (.*)
it will match the whole line and what you want to do is break it down somehow so that you can extract the string you want to keep. Here, I have done exactly the same and it works fine in Notepad++ and Editplus3.
Solution 4
There are two problems with your original solution. Firstly, your example text:
<option value value='1' >A
has two occurences of the "value" word. Your regex does not. Also, you need to escape the opening brace in the quantifier of your regex or Vim will interpret it as a literal brace. This regex works:
:%s/<option value value='.\{1,}' >//g
Solution 5
This will remove the option
tag and just leave the letters in vim:
:%s/<option.*>//g
SCoder
Updated on May 09, 2020Comments
-
SCoder almost 4 years
here's my task: I want to sum the digits of an int, problem is I don't know how many digits there are (and I can't ask the user). Is there anything like a getchar for int? I've also tried int c = getchar(), but it isn't working. Thanks:)
I wanted it to be a recursive function, but I guess it is just wrong.
I THINK I GOT IT, THANKS EVERYONE!
int sum_digits (int n) { int answer = 0; if (getchar() == 0) { return answer; } else { int c = getchar(); return answer = c + sum_digits(n); }
}
-
Gopi about 9 yearsShow what you have tried
-
BLUEPIXY about 9 yearsThere was a question that was similar to the past.
-
pmg about 9 years
0b 11111111 11111111 11111111 11111111
or0xFFFF
or65535
? Notice all the representations are for the same value. -
ashiaka about 9 yearsyou can solve this by using the modulo operator in combination with division. (i.e. calculate modulo 10 to get the value of the last digit, then devide the number by 10, then again modulo 10, etc.)
-
Martin James about 9 yearsWhat @ashiaka says. Time for some recursion - keeps the prof happy.
-
Jongware about 9 yearsI can personally testify that "int c = getchar()" works the way it should. You are using it for another (wrong) purpose, which is generally not recommended.
-
SCoder about 9 years@ashiaka I have read that answer before, but I just don't see how that can be recursive. Like how do I know when to stop diving If I don't know how many digits there are and if I can't count digits separately and give that value to my function as a parameter?
-
Jean-Baptiste Yunès about 9 yearsdivide by ten, then by ten, etc. until 0, you will be able to compute the number of digits! Ex: 1234/10 = 123, 123/10=12, 12/10=1, 1/10=0, fours divisions by ten, then four digits.
-
unwind about 9 years@SCoder How many digits are there in the number 0?
-
Jean-Baptiste Yunès about 9 yearsHey, this is not the sum of the digits of an int! This is the sum of the digits of the char representation of an int... And your answer is wrong!
-
SCoder about 9 years1, I understand my mistake.
-
BLUEPIXY about 9 years@pmg
0b 11111111 11111111 11111111 11111111
-->0b 11111111 11111111
-