regex - leading (?!\w) doesn't work with locale characters [duplicate] - javascript

This question already has answers here:
Regex whitespace word boundary
(3 answers)
Javascript RegExp + Word boundaries + unicode characters
(15 answers)
Closed 26 days ago.
Context: I'm using a library (markjs.io) to mark specific words. My current solution let rgx = /(?:^|\s)žolč iz žrela([\s.!?,:;])/i; also marks the leading space and trailing space and separators.
I've come up with a solution which is very close, but the leading (?!\w) allows characters to be adjacent to the word.
Current "solution" which allows adjacent characters - (?!\w)[žŽ]olč iz žrela(?!\w)
Example can be found here, on regex101.
Any help would be greatly appreciated.
If I can elaborate or if you find a flaw, please let me know. Thank you

Related

Non-greed regex misunderstanding, /\/.*?$/ act like greed [duplicate]

This question already has answers here:
Regex lazy vs greedy confusion
(2 answers)
Why does a simple .*? non-greedy regex greedily include additional characters before a match?
(3 answers)
Closed 3 years ago.
I'm trying this in javascript
/\/.*?$/.exec('foo/bar/tar')[0]
I was expecting to get /tar as result but getting /bar/tar. As far as I understand non-greed regex would take the smallest match.
I'm circumventing this with myvar.split('/').reverse()[0] but I couldn't understand what is going wrong with the regex.
There is nothing wrong with the regex but the pattern \/.*?$ matches from the first forward slash until the end of the string non greedy.
The dot matches any character except a newline and does not take a forward slash into account, so that will result in /bar/tar.
If you want to match /tar, you could match a forward slash, followed by not matching anymore forward slashes using a negated character class and then assert the end of the string.
\/[^\/]+$
Pattern demo
console.log(/\/[^\/]+$/.exec('foo/bar/tar')[0]);

Word boundary not working for amount in dollars (REgex) [duplicate]

This question already has answers here:
how to reduce complexity in regex?
(3 answers)
Closed 5 years ago.
I have a regex which will match amount in $.
(\-?\$\-?[0-9]+\.?[0-9]*|usd\-?[0-9]+\.?[0-9]*|[0-9]+\.?[0-9]*\-?usd|[0-9]*\.?[0-9]*\$)
Currently its matching for $250, USD250 etc, it should not match the $250 in $250abchhh.
So, I tried word boundary, but it didn't fix the issue as well, how can I fix this issue?
matching cases are
$456
$45.6
$.5
$-45
-$45
usd-456
usd46
usd4.6
usd.46
1$
1.5$
.5$
-.5$
5usd
456usd
it should not match
455$abc
abc$123
abcuds1
jhb$5665usdjnjnb
$usd1555
usd$768
$566usd
$5788usdbjhj
You should also write a correct regex for a decimal. And use ^$ for start and end of line.
^\s*(?:(?:(?:-?(?:usd|\$)|(?:usd|\$)-)(?:(?:0|[1-9]\d*)?(?:\.\d+)?(?<=\d)))|(?:-?(?:(?:0|[1-9]\d*)?(?:\.\d+)?(?<=\d))(?:usd|\$)))\s*$
Look here at the test results.

Regex query, description [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 5 years ago.
I have a regex query for password verification, the rules are password must be between 8-15 chars, 1number + 1 special characters. It is working perfectly in web form.
I only need to understand it fully. If anyone can help me in describing this regex group by group,, it will be of great help to me. I do understand some part but not all.
^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{7,15}$
Since you updated the regex...
^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{7,15}$
^(?=.*[0-9]) from the start of the string, match any numbers. The lookahead ?= prevents the regex from continuing if nothing matches.
(?=.*[!##$%^&*]) match any special characters in the group.
[a-zA-Z0-9!##$%^&*] capture all letters, numbers, and special characters. At least 7 and up to 15 until the end of the line.

Regex for alphanumerical characters but also other alphabets such as Chinese, Japanese, Cyrillic [duplicate]

This question already has answers here:
Regular expression with the cyrillic alphabet
(4 answers)
Closed 6 years ago.
my knowledge with Regex is limited and I'm trying to keep the text of the following sentence but remove the special characters such as dashes:
Λένα & Πλάτωνος - Red Axes Remixes
Sugai Ken 鯰上 - On The Quakefish
Anyone knows how to deal with different alphabets?
I tried ([^\w'])+ but it removes the essential characters...
Thanks!
You could try something like this:
`[^\x00-\x1F\x21-\x7F]*
This should match anything not in the regular ascii set and space. You can update that to include whatever other regualar ascii characters you would like to include. As you can see, I have 1 ranges, so that it includes the 'space' character.
Obviously, you could go the other way around and do an inclusive match, making it easier to include the exact characters to match:
`[\x80-\x{FFFF} &]*

RegEx: non-consecutive special characters only allowed in the middle [duplicate]

This question already has answers here:
Regex to find not start and end with dot and allow some special character only not all
(3 answers)
Closed 2 years ago.
I am using following
ng-pattern="/^[a-zA-Z][a-zA-Z0-9._](.*[a-zA-Z0-9])?$/"
The matching String should
not start with a special character,
not end with special character, and
not include consecutive symbols except . (dot) and _ (underscore).
But it is not working.
Please, any suggestion.
Try using the word character class as a start ([\w] = [a-zA-Z0-9_]):
I'm not sure what you mean by consecutive symbols. But this might help:
/^[a-zA-Z]([\w.]*[a-zA-Z0-9])?$/
Maybe, have a look at the JavaScript RegExp Reference

Categories

Resources