EzDevInfo.com

xregexp

Extended JavaScript regular expressions JavaScript Regex :: XRegExp

Password Regex with XRegExp

I have a client-side validation regex for a password field which should allow alphabets in all languages supported by Unicode.

This is the existing regex for password:

(?=^.{8,21}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*[A-Z])(?=.*[a-z])

I am using the XRegExp library, and i have tried modifying the regex to include \p{L} but I am unable to get it to pass for passwords like "Ss!11111".

Below is my modified regex:

(?=^.{8,21}$)((?=.*\d)|(?=.*\W+))(?![.\n])(?=.*\\p{L})

I know this question might seem stupid, but i currently have very little time to experiment with this regex. Would be really helpful if someone helped me out and pointed me in the right direction.


Source: (StackOverflow)

How do I select everything after a certain position using REGEXP in Oracle

I am using Oracle 11G and I have the following string: I - Am in- Need Help- Please and want to parse the string using the - character then select everything after the second object. I have been playing around with REGEXP_REPLACE and SUBSTR and I can select the second object but can't seem to select everything after the second object. I know I need to add a * somewhere I think but I can't seem to get the syntax correct. Any help would be greatly appreciated.

SELECT REGEXP_SUBSTR ('I - Am in- Need of Help- Please', '[^-]+' , 1, 2) 
  FROM DUAL;

The above query returns the second object 'Am in' but I want this returned 'Need of Help- Please'. It is also important to note that I don't want the - character directly following the second object in the result either but I want to start with the third object.


Source: (StackOverflow)

Advertisements

XRegExp to JavaScript RegExp

I want to convert a XRegExp function to pure JavaScript RegExp. Basically all non-alphanumeric character will be replaced with "_" including spaces.

The text

This is a sample text *\&^%$#@!~'

will be like

This_is_a_sample_text____________

I have the following code.

var text = "This is a sample text *\&^%$#@!~'";
var matchAlphaNumeric = new XRegExp('[\\p{L}\\p{N}]');
var result = substituteNotAcceptedCharactersforTag(text, matchAlphaNumeric);
function substituteNotAcceptedCharactersforTag(text, regex) {
        var tagWithAlphaAndNumeric = '';
        for (var i = 0; i < text.length; i++) {
            var characterBeingTested = text.charAt(i);
            if (XRegExp.test(characterBeingTested, regex) === true) {
                tagWithAlphaAndNumeric += characterBeingTested.toLowerCase();
            } else {
                tagWithAlphaAndNumeric += '_';
            }
        }
        return tagWithAlphaAndNumeric;
    }

Source: (StackOverflow)

jquery validator addmethod xregexp case insensitive

I'm trying to test a string using jquery.validator and xregexp but I need to be able to dynamically set a flag for case insensitivity. Problem is I don't know how to send the flags for my xregexp to the addmethod using a param. Here is what my addmethod currently looks like:

$.validator.addMethod(
    "regex",
    function(value, element, regexp) {
        var re = new XRegExp(regexp);
        return this.optional(element) || re.test(value);
    },
    "Please check your input."
);

And here is my call to it:

webAddr: {
    regex: '^(http(s)?:\/\/)?(([a-z]+[a-z0-9-\\.]*)\\.)+[a-z]{2,}$\\i',
    maxlength: 256,
    minlength: 4
},

My problem is the \\i. I want to include it but according to the docs you have to include it as a separate param using this format:

XRegExp(regexp, flags);

How do I do I pass that dynamic using jquery.validator?

PS: The reason I'm using xregexp and not something else is because I need true UTF-8 support elsewhere in my code, so I try to stick to using it for everything to help me get more proficient with it.


Source: (StackOverflow)

Splitting unicode sentence into words array using XRegExp

I'm using following script for splitting Unicode sentence into words array.

XRegExp.matchChain("læseWEB læser teksten på dit website op.", [XRegExp("[\\p{Alphabetic}\\p{Nd}\\{Pc}\\p{M}]+", "g")])


[ "læseWEB", "læser", "teksten", "på", "dit", "website", "op" ]

Now I'm expecting

['læseWEB ', 'læser ', 'teksten ', 'på ', 'dit ', 'website ', 'op.'].

Someone said I need to use split function instead of matchChain.

Any suggestions?


Source: (StackOverflow)

Regex for a recursive grammar in javascript

Suppose I have the following fictional grammar, with a recursive definition for clause.

sentence := clause +
subject := (qualifier *) subjectiveNoun
objects := object +
object := nothing | (qualifier *) objectiveNoun
clause := subject objects verb
qualifier := adjective | clause

Assuming everything else has a non recursive definition, how should can approach writing a javascript grammar for 'clause'? If someone is familiar with the XRegExp library to do this, that would be an added plus.


Source: (StackOverflow)

javascript regex support for UTF8 characters with Number and letters

How to generate regex for supporting utf8 characters with Numbers [0-9], letters [a-z] and [A-Z].

I am using xregexp library to support utf-8 characters.

Till now i used :

  1. XRegExp("^\p{L}\d{0-9}+$") //Not supporting any of them.
  2. XRegExp("[^\p{N}\p{L}]") //Not supporting any of them.
  3. XRegExp("^\p{L}+$") // Supports only UTF-8 characters, [a-z] and [A-Z] and not [0-9]

Thanks.


Source: (StackOverflow)

Is XRegExp compatible with RequireJS?

I downloaded RequireJS single page app sample. In the www/lib folder, I put the XRegExp source xregexp-all.js (version 2.0.0).

In www/app/main.js, I added:

var xregexp = require('xregexp-all');
print(typeof(xregexp));

The console output is:

undefined

However, requireJS doesn't emit any error messages. Am I doing something wrong?


Source: (StackOverflow)

XRegExp: negate expression

What is the negate expression of following XRegExp expression?

[\\p{Alphabetic}\\p{Nd}\\{Pc}\\p{M}]+

I used matchChain() to get the words out of the sentence using above expression.

Now I'm going to use split() using negate expression to get the same result but with containing delimiters for each words.


Source: (StackOverflow)

How to create Regular expression to Omit Unicode character 'θ'?

I have created a regular expression to support UTF8 characters :

XRegExp("^(\\p{L}|[0-9_/-]|\\s)+$");

Now, i don't want to support unicode character : 'θ' (theta).


Source: (StackOverflow)

XRegExp regular expression to allow single space between characters

I am working with XRegExp Regex. I would like to have a space between my character also I need to have special characters enables. I have managed to add special characters allowed but I am not able to have a space allowed.

My regex unicodeWord = XRegExp("^(\\p{L}|[0-9][\s])+$");

It allows character like

Wèlcome

but not

Hi Wèlcome

//Alphanumeric validation
function isAlphanumeric(str) { 
    var unicodeWord = XRegExp("^[\p{L}\d]+(?:\s+[\p{L}\d]+)*$"); 
    result = unicodeWord.test(str);
    return result;
}


été altérée sûr générateurs

But this dosnt match this Alphanumeric.


Source: (StackOverflow)

Validating UTF-8 names in JavaScript (Node.js) with XRegExp

I'm trying to check if a given UTF-8 string consists of letters only.
I tried the solution I found here: Validating user's UTF-8 name in Javascript

Given string: Ciesiołkiewicz
is tested with var XRegExp = require('xregexp').XRegExp('^\\p{L}+$');

And it's not working because of "ł" letter
I tried XRegExp('^[\\p{Latin}\\p{Common}]+$');
but it's too much, it accepts polish letters but also characters like "$" etc

How can I validate it against letters only? I don't want to type them into regexp manually.


Source: (StackOverflow)

XRegExp to match Greek whole words

<html>
<head>
        <title>Test</title>
        <meta charset="UTF-8">

<script src="xregexp.js"></script>
<script src="unicode-base.js"></script>
<script src="unicode-scripts.js"></script>
<script>
var wordsToMatch = "Gr|Greek|ΕΛΛΗΝΙΚΑ";

var regexPattern = '\\b('+wordsToMatch+')';

var referenceRegex = new XRegExp(regexPattern, 'mi');
//var testString = "ΕΛΛΗΝΙΚΑ"; //null  -  ???
var testString = "Gr"; //Gr,Gr  -  OK AS IT SHOULD
var match = referenceRegex.exec(testString); 

function myFunction()
{
    alert(match);
}
</script>

</head>
<body onload="myFunction()">


</body>
</html>

I believe my example is quite explainable, it matches fine english words, I would like to match also Greek words too. I am not familiar with the unicode add-on of xregexp, my pattern was implemented to work with regexp.


Source: (StackOverflow)

How to create Regular expresssion for supporting xregexp for supporting UTF8 characters and some other characters

I want support Numeric, Alphabetic, special, and unicode characters. Here, what i have created the Regexp.

var regex = XRegExp("^(\\p{L}|([A-Za-z0-9\!\@\$\%\&\-\=\+\*\#\;\:\,\.\/\?]))+$");

regex.test(αβγδεζηθ); //returns false >> Non-ASCII characters entered
regex.test(αa@123); //returns false
regex.test(ab@123); //returns true

The above expression is not supporting utf8 characters. Please help. The special characters defined in regexp are valid and they are supporting but utf8 characters are not supporting.

I am not able to identify where is the problem.

Please help.


Source: (StackOverflow)

JS XRegExp Replace all non characters

My objective is to replace all characters which are not dash (-) or not number or not letters in any language in a string.All of the #!()[], and all other signs to be replaced with empty string. All occurences of - should not be replaced also. I have used for this the XRegExp plugin but it seems I cannot find the magic solution :) I have tryed like this :

var txt = "Ad СТИНГ (ALI) - Englishmen In New York";
var regex = new XRegExp('\\p{^N}\\p{^L}',"g");
var b = XRegExp.replace(txt, regex, "")

but the result is : AСТИН(AL EnglishmeINeYork ... which is kind of weird

If I try to add also the condition for not removing the '-' character leads to make the RegEx invalid.


Source: (StackOverflow)