Viewed   86 times

I have this English and Arabic regex in php , it works fine with php

But its not working with this library Formvalidation.io

~^[a-z0-9?-?-+,()/'sp{Arabic}]{1,}$~iu

I need to make it work and convert into JS regex to use in formvalidation regex.

Demo Regex 101

 Answers

5

The Arabic regex is:

[u0600-u06FF]

Actually, ?-? is a subset of this Arabic range, so I think you can remove them from the pattern.

So, in JS it will be

/^[a-z0-9+,()/'su0600-u06FF-]+$/i

See regex demo

Tuesday, October 11, 2022
1
"/<script((?:(?!src=).)*?)>(.*?)</script>/smix"

(My first look-ahead regex ;))

Please note that you should not parse HTML with regexes, see:

https://.com/a/1732454/221213

Saturday, August 6, 2022
 
octern
 
1

JavaScript uses the syntax uhhhh (exactly 4 hexadecimal digits) to specify an UTF-16 code unit in the regular expression. For characters in BMP range, except for the range D800-DFFF, the code point of the character maps directly to one UTF-16 code unit which has the same value of the code point. This is exactly the case here, so we don't need to deal with surrogate and its quirks.

In this case, just replace x{h...hh} syntax from PCRE (in PHP) with uhhhh syntax:

var PREG_CLASS_UNICODE_WORD_BOUNDARY = [
    "\u0000-\u002F\u003A-\u0040\u005B-\u0060\u007B-\u00A9\u00AB-\u00B1\u00B4",
    "\u00B6-\u00B8\u00BB\u00BF\u00D7\u00F7\u02C2-\u02C5\u02D2-\u02DF",
    "\u02E5-\u02EB\u02ED\u02EF-\u02FF\u0375\u037E-\u0385\u0387\u03F6",
    "\u0482\u055A-\u055F\u0589-\u058A\u05BE\u05C0\u05C3\u05C6",
    "\u05F3-\u060F\u061B-\u061F\u066A-\u066D\u06D4\u06DD\u06E9",
    "\u06FD-\u06FE\u0700-\u070F\u07F6-\u07F9\u0830-\u083E",
    "\u0964-\u0965\u0970\u09F2-\u09F3\u09FA-\u09FB\u0AF1\u0B70",
    "\u0BF3-\u0BFA\u0C7F\u0CF1-\u0CF2\u0D79\u0DF4\u0E3F\u0E4F",
    "\u0E5A-\u0E5B\u0F01-\u0F17\u0F1A-\u0F1F\u0F34\u0F36\u0F38",
    "\u0F3A-\u0F3D\u0F85\u0FBE-\u0FC5\u0FC7-\u0FD8\u104A-\u104F",
    "\u109E-\u109F\u10FB\u1360-\u1368\u1390-\u1399\u1400",
    "\u166D-\u166E\u1680\u169B-\u169C\u16EB-\u16ED",
    "\u1735-\u1736\u17B4-\u17B5\u17D4-\u17D6\u17D8-\u17DB",
    "\u1800-\u180A\u180E\u1940-\u1945\u19DE-\u19FF",
    "\u1A1E-\u1A1F\u1AA0-\u1AA6\u1AA8-\u1AAD\u1B5A-\u1B6A",
    "\u1B74-\u1B7C\u1C3B-\u1C3F\u1C7E-\u1C7F\u1CD3\u1FBD",
    "\u1FBF-\u1FC1\u1FCD-\u1FCF\u1FDD-\u1FDF\u1FED-\u1FEF",
    "\u1FFD-\u206F\u207A-\u207E\u208A-\u208E\u20A0-\u20B8",
    "\u2100-\u2101\u2103-\u2106\u2108-\u2109\u2114",
    "\u2116-\u2118\u211E-\u2123\u2125\u2127\u2129\u212E",
    "\u213A-\u213B\u2140-\u2144\u214A-\u214D\u214F",
    "\u2190-\u244A\u249C-\u24E9\u2500-\u2775\u2794-\u2B59",
    "\u2CE5-\u2CEA\u2CF9-\u2CFC\u2CFE-\u2CFF\u2E00-\u2E2E",
    "\u2E30-\u3004\u3008-\u3020\u3030\u3036-\u3037",
    "\u303D-\u303F\u309B-\u309C\u30A0\u30FB\u3190-\u3191",
    "\u3196-\u319F\u31C0-\u31E3\u3200-\u321E\u322A-\u3250",
    "\u3260-\u327F\u328A-\u32B0\u32C0-\u33FF\u4DC0-\u4DFF",
    "\uA490-\uA4C6\uA4FE-\uA4FF\uA60D-\uA60F\uA673\uA67E",
    "\uA6F2-\uA716\uA720-\uA721\uA789-\uA78A\uA828-\uA82B",
    "\uA836-\uA839\uA874-\uA877\uA8CE-\uA8CF\uA8F8-\uA8FA",
    "\uA92E-\uA92F\uA95F\uA9C1-\uA9CD\uA9DE-\uA9DF",
    "\uAA5C-\uAA5F\uAA77-\uAA79\uAADE-\uAADF\uABEB",
    "\uE000-\uF8FF\uFB29\uFD3E-\uFD3F\uFDFC-\uFDFD",
    "\uFE10-\uFE19\uFE30-\uFE6B\uFEFF-\uFF0F\uFF1A-\uFF20",
    "\uFF3B-\uFF40\uFF5B-\uFF65\uFFE0-\uFFFD"].join('');
Tuesday, August 30, 2022
 
5

Nothing really special. PHP regex syntax is very much the same as in JavaScript:

str = str.replace(/(d*)|/(P)//g, "");

You can find more information about regular expressions in JavaScript in this manual from MDN: https://developer.mozilla.org/en-US/docs/JavaScript/Guide/Regular_Expressions.

Sunday, August 21, 2022
 
5

regex101

([A-Z][^s]*)

Debuggex Demo


Description

1st Capturing group ([A-Z][^s]*)  
    [A-Z] match a single character present in the list below  
        A-Z a single character in the range between A and Z (case sensitive)
    [^s]* match a single character not present in the list below
        Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
        s match any white space character [rntf ]
g modifier: global. All matches (don't return on first match)

Full Sentence

^(?:[A-Z][^s]*s?)+$

Debuggex Demo

Description

^ assert position at start of the string
(?:[A-Z][^s]*s?)+ Non-capturing group
    Quantifier: + Between one and unlimited times, as many times as possible, giving back as needed [greedy]
    [A-Z] match a single character present in the list below
        A-Z a single character in the range between A and Z (case sensitive)
    [^s]* match a single character not present in the list below
        Quantifier: * Between zero and unlimited times, as many times as possible, giving back as needed [greedy]
        s match any white space character [rntf ]
    s? match any white space character [rntf ]
        Quantifier: ? Between zero and one time, as many times as possible, giving back as needed [greedy]
$ assert position at end of the string
Thursday, October 20, 2022
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :