Regex and Javascript : find word with accents [duplicate] - javascript

This question already has answers here:
How can I use Unicode-aware regular expressions in JavaScript?
(11 answers)
Closed 8 years ago.
I try to find and stock in HTML paragraphe all the word.
Actually, I have a function like this
p.html(function(index, oldHtml) {
return oldHtml.replace(/\b(\w+?)\b/g, '<span>$1</span>');
});
But it's only return word without accent.
I test on regex101.com
https://www.regex101.com/r/jS5gW6/1
Any idea ?

Use a character class:
oldHtml.replace(/([\wàâêëéèîïôûùüç]+)/gi, '<span>$1</span>');
Trying it:
var oldHtml = 'kjh À ùp géçhj ùù Çfg';
var res = oldHtml.replace(/([\wàâêëéèîïôûùüç]+)/gi, '<span>$1</span>');
gives
"<span>kjh</span> <span>À</span> <span>ùp</span> <span>géçhj</span> <span>ùù</span>
Çfg"

Related

Extract text from enclosing parentheses using JavaScript [duplicate]

This question already has answers here:
Get text between two rounded brackets
(7 answers)
Closed 2 years ago.
I have a string like Manila (Philippines) and want to replace it with only the substring Philippines. I tried using the following regex pattern, which works in Notepad++:
[^\(]+ \(([^\)]+)\)
However, I get an undefined result in JavaScript:
var x = "Manila (Philippines)";
console.log(x.replace(/[^\(]+ \(([^\)]+)\)/,$1));
You just forgot the " around your replace pattern!
console.log(x.replace(/[^\(]+ \(([^\)]+)\)/,"$1")); will work correctly!
You can use .match():
var x = "Manila (Philippines)";
var result = x.match(/\((.+)\)/).pop();
// regex for string contained in parentheses
console.log(result);

Python Regex to get string(extension) after special character [duplicate]

This question already has an answer here:
Extract until end of line after a special character: Python
(1 answer)
Closed 5 years ago.
I have a string want to get string after special character which is extension.
i tried and it is works fine in javascript but wasnt in python.. how to do that?
here is my JS snippet,
my_str_0 = ".exr[6,7]";
my_str_1 = "/home/mohideen/test_dir/Samp_8860-fg_paint_%04d.exr[6] 1-7";
my_str_2 = "/home/mohideen/test_dir/Samp_8860-fg_paint_%05d.png[1] 1-10";
my_str_3 = "/home/mohideen/test_dir/Samp_8860-fg_paint_%05d.jpg";
for (var i in [my_str_0, my_str_1, my_str_2, my_str_3]) {
var reg = /([^.]*)$/.exec(eval("my_str_"+i));
console.log(reg[0]);
}
here is my python regex link
Use MultiLine Flag.
See here in this link

I need How to split this string in javascript? [duplicate]

This question already has answers here:
Regular Expression to find a string included between two characters while EXCLUDING the delimiters
(13 answers)
Closed 5 years ago.
var faxNum = $("#txt_faxnum").val();
//Value : ""kekurt kekt809" <(732) 588-8300>"
I want to split between "< >". Example: Just I need to this section : (732) 588-8300
How to split this string ?
You can try this
var String=faxNum.substring(str.lastIndexOf("<")+1,faxNum.lastIndexOf(">"));

Javascript regex in attribute [duplicate]

This question already has answers here:
Create RegExps on the fly using string variables
(6 answers)
Closed 8 years ago.
I need to use data attribute for regex just as
<div data-regex="REGEX-HERE">
and then get the value by javascript and put in a variable. and then do a test like
var regex = $(this).attr("data-regex");
regex.test(name)
when I tried to use "^[\x20-\x7E]+$" for testing english character is didn't work.
Note when I tried this
var regex = /^[\x20-\x7E]+$/;
It worked.
Thanks in advance
You can do this:
var regex = new RegExp("^[\x20-\x7E]+$",""); // Modifiers on the tend
So finally:
var regex = new RegExp($(this).data("regex"));
regex.test(name)

How to downcase all char and uppercase only the first characters via js? [duplicate]

This question already has answers here:
How do I make the first letter of a string uppercase in JavaScript?
(96 answers)
Closed 8 years ago.
Now I have this regex:
tSzoveg = tSzoveg.replace(/\b[A-Z]{2,}\b/,'');
It is almost that I want. I want to convert this: THIS IS MINE, NOT YOURS. to this: This is mine, not yours.
How can I convert it to a normal sentence?
function capitalize(string)
{
return string.toUpperCase().charAt(0) + string.toLowerCase().slice(1);
}
I would use toLowerCase() and then modify the first letter:
var str = "THIS IS MINE, NOT YOURS."
str.charAt(0).toUpperCase() + str.slice(1).toLowerCase();

Categories

Resources