How can I use Regular Expression to match Chinese characters like ,。‘;’ [duplicate] - javascript

This question already has answers here:
Regular expression to match non-ASCII characters?
(8 answers)
Closed 5 years ago.
I'm using javascript to convert string to what I want!!
Can I use Regular Expression and use what Regular Expression??
Is there anyone that can help me?

First, you need to get corresponding Unicode code for these Chinese characters. Here is a helpful tool.
character code(base 10) code(hex)
, 65307 0xff1b
。 65292 0xff0c
; 12290 0x3002
Second, use these Unicode code to form regexp.
js:
/[\u3002\uff0c\uff1b]/.test('A string contains Chinese character。')
true

Related

Regex Unexpected ^ and character match [duplicate]

This question already has answers here:
Javascript: Split a string into array matching parameters
(3 answers)
Closed 4 years ago.
I have this regular expression that tokenizes calculator input strings like 12+3.4x5 to 12,+,3.4,x,5
The regular expression used is
\d+\.?\d+|[\+-÷x]
I get an unexpected match with ^ and letters.
Regex solution, although there's probably a cleaner way of writing this if someone could point it out?
(\d+\.?\d+|\d+|(\+|-|÷|x))

REGEX javascript - find two chars set [duplicate]

This question already has answers here:
What special characters must be escaped in regular expressions?
(13 answers)
Closed 5 years ago.
i've to find the sequence of chars ,. inside a json file for example: ":0,.0}},{", so what is the best fitted regex string for it?
i tried /(,.){1,}/g but it doesn't work well.
It's because . is a special character.
const r = /(?:,\.)+/g
console.log('abc,.,.,.def'.match(r)) //[",.,.,."]
you need to escape the .:
/,\./g

JavaScript special characters misunderstanding [duplicate]

This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 8 years ago.
In this javascript code I have this row:
var regex = /\s+/gi;
Any idea what is the maning of this:
/\s+/gi
Thank you in advance.
Here is a must read for same https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions
Regular expressions are patterns used to match character combinations in strings. In JavaScript, regular expressions are also objects. These patterns are used with the exec and test methods of RegExp, and with the match, replace, search, and split methods of String. This chapter describes JavaScript regular expressions.
Here, each contiguous string of space characters is being replaced with the empty string
For more details refer :-
Is there a difference between /\s/g and /\s+/g?

Javascript regex to extract the string before the last backslash [duplicate]

This question already has answers here:
Regex for everything before last forward or backward slash
(3 answers)
Closed 9 years ago.
I am dealing with timezone's in Javascript and I need a regex that will extract everything, but the timezone name from it. For example, I have the timezone America/Argentina/Buenos_Aires. I want to extract the America/Argentina part with a regex. Currently I have this regex: tz.match(/.*?(?=\/|$)/i)[0] which extracts everything to the first backslash which works for most timezones (America/Los_Angeles), but not for all of them. How could I edit that regex so that it gets the string before the last value?
I'd personally suggest avoiding regular expressions for something like this, when simple string functions/methods would suffice admirably:
var stringVariable = 'America/Argentina/Buenos_Aires',
text = stringVariable.substring(0, stringVariable.lastIndexOf('/'));

Allowing non-latin characters with regex [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Regular expression to match non-english characters?
I am using this regex to limit some characters.
I wanted to change this to allow all latin and non-latin letters but i think regex is not my think : )
String.prototype.isText2 = function () {return /^[\.\-\w\s&']*$/.test(this)}
This regex only allows latin chars and ' and & i think.
How can i make it allow non-latin letters ? (like these ç,ü,ğ,ş and chinese,japanese, arabic)
You can use XRegExp. This supports Unicode.
You will need to work with unicode values. Please take a look at this previous SO thread for more information.

Categories

Resources