I'm trying to match the second dot in a number to replace it later with a white space in my 'find and replace' function in Aptana.
I tried a lot of expressions, none of them worked for me.
For example I take the number:
48.454.714 (I want to replace the dot between 454 and 714)
Try this regex:
(\d{3})\.(\d{3})
and replace the first and second capturing group \1 \2
as mentioned by FiveO, you might want to match other numbers of digits too. E.g. one to 3 digits: \d{1,3} or any number of digits: \d+
Try with following regex:
\d+\.\d+(\.)\d+
And replace it with white space.
Related
I'm trying to create an expression to collect anything but digits and the character *. I tried to use the expression \D[^*] but somehow it's retrieving the first digit after blank espaces. I tried this expression with the string 1234 1234 1234 **** and the matches were: ' 1', ' 1'. Can anyone tell me why would the expression collect the digits with the blank spaces?
Thank you.
Your regex ('\D[^*]') will match a Space (thats' not a digit) followed by a digit (that's not a star '*').
You can do several Things, the easiest is to include '\d' in the character Group, then it will Work, because both '\d' and '*' are excluded:
/[^\d*]/g
Now it will only match Spaces in your example.
A square brackets in regex are a set, and a square bracket with ^ mean not in set.
The \d should also be inside the brackets:
[^\d*]
https://regex101.com/r/WizvVh/1
I have a text:
Wheels – F/R_ Schwalbe TABLE TOP/Schwalbe Black Jack 26x2.2
And regex to parse wheels size from that string:
/.*Wheels.*(\d*)x/
But it does not work. Besides, when i'm removing asterisk from regex, i'm getting number 6 as group match.
You need to make your .* before the digits lazy instead of greedy:
/.*Wheels.*?(\d*)x/
The .* will greedily consume everything up to the x, leaving nothing for the following \d*. Since * can validly match zero characters, an empty match for \d* is not an incorrect result.
By adding a ? to make a lazy .*? expression, it will try match as few characters as possible, allowing the following \d* to match all the numbers before the x.
You need to make your regex non-greedy because .* will consume your digits and \d* mean zero or no match
.*Wheels.*?(\d*)x
.*? mean match as many characters as few time as possible to stop .* to consume your digits
Follow this Demo for example
Alternately you can make it more efficient if there are no digits after Wheel and your desired values with following regex
.*Wheels[^\d]*(\d*)x
where [^\d]* mean matches anything except digits
I need some help writing regex.
this is my first regex expression(match either English or Hebrew chars):
/^(?:[\u0590-\u05FF\uFB1D-\uFB40]+|[\w]+)$/i
this should be match: abc, אבג
this should not be match:a , b, aא
It works ok, I just need to also add limitaion for more then 1 char.
The next one should be exactly like the one above(including the more than 1 char
limitation) but to also allow spaces.
this should be match: abcx, abcx ascx, דגהק , שגד דשגב
this should not be match:a , b, asaceדגעההת, ascasv אקיכרעקכ
The last Regex expression should be all digits, contain exactly 10 digits
and to start with the numbers 05.
this should be match: 0528547114
this should not be match: digits, special chars, less or more than
10 digits.
I'm using JS and C# Regex.
Any help would be much appreciated.
To match more than 1 character use the quantifier {2,} instead of +:
/^(?:[\u0590-\u05FF\uFB1D-\uFB40]{2,}|[\w]{2,})$/i
To match space, add it in the character class:
/^(?:[\u0590-\u05FF\uFB1D-\uFB40 ]{2,}|[\w ]{2,})$/i
To match 10 digits:
/^(?:[\u0590-\u05FF\uFB1D-\uFB40 ]{2,}|[\w ]{2,}|05\d{8})$/i
To match several words separated by one space:
/^(?:[\u0590-\u05FF\uFB1D-\uFB40]{2,}(?: [\u0590-\u05FF\uFB1D-\uFB40]{2,})*|\w{2,}(?: \w{2,})*|05\d{8})$/i
What is the regex for detecting a specific word preceded by any combinations of numbers?
Example:
123 Box
1 Box
21245 Box
The word should match, now you need to do digits [0-9] or \d followed by the + which is one or more:
box [0-9]+
or
box \d+
/[0-9]+[bB]ox/ should work for this
You could use a regex like this:
\b(\d+ box)\b
Working demo
The idea of the regex is to capture the numbers and the box word, so using \b (word delimiter) it will exclude words like boxer and also exclude invalid numbers like a123. Note that I used the insensitive flag, so if you need a case sensitive match just remove the i flag and use \b(\d+ Box)\b instead.
Match information:
MATCH 1
1. [27-34] `123 Box`
MATCH 2
1. [35-40] `1 Box`
MATCH 3
1. [41-50] `21245 Box`
If you don't want to capture the content and only match the pattern you have to remove the parentheses.
I want to restrict the user from entering same consecutive digits in a text field e.g User can't enter string like John22 or 22John or jo22hn....He can enter string like Joh2n2 , 2Joh2n and so on...All this has to be done in Javascript (Using regular expressions would be a better option)...Please help
Test a string for consecutive digits:
/(\d)\1/.test(string)
You can do this by using a negative lookahead.
^(?!.*(\d)\1).*$
See it here at Regexr
The ^ and the $ anchor the match at the start and the end of the string.
.* Will match everything (except newline characters)
The important part here is the Negative lookahead (?!.*(\d)\1) it will check the whole string for a digit \d put it in a capture group because of the brackets (\d) and reuse the value using the backreference \1 and the whole thing fails it there is a digit followed by the same digit.
The following regex should help:
/[0-9]{2,}/
Or
/[\d]{2,}/
Although, you can match for all instances using the /g flag:
/[0-9]{2,}/g
See it at this JSFiddle