RegExp for Hangul in Ruby [duplicate] - regex

This question already has answers here:
What is proper way to test if the input is Korean or Chinese using JavaScript?
(2 answers)
Closed 4 years ago.
How do you find Korean letters using regex in JavaScript?

You can use the following regex
const re = /[\u3131-\uD79D]/ugi
This is the code table that I referenced: http://memory.loc.gov/diglib/codetables/9.3.html
Try it yourself:
const re = /[\u3131-\uD79D]/ugi
console.log("abcde".match(re)) // null
console.log("안녕".match(re)) // ["안", "녕"]

Related

How to use pandas extract to remove string in a pandas column [duplicate]

This question already has an answer here:
Python Regular Expressions for a question mark [duplicate]
(1 answer)
Closed 10 months ago.
I have this dataframe:
d = pd.DataFrame({'test':['test?_Apple','test?_Banana', 'test?_limon']})
And I want to remove the test?_ string from test columns values to get this:
d = pd.DataFrame({'test':['Apple','Banana', 'limon']})
I am trying:
d['test'] = d['test'].str.extract(r'test?_(.*)')
but it returns NAN
Can someone help me on this one?
Escape ? because special regex character:
d['test'] = d['test'].str.extract(r'test\?_(.*)')

Invalid match for regex ('\pL' does not work within a character class) [duplicate]

This question already has answers here:
Matching Unicode letter characters in PCRE/PHP
(5 answers)
Closed 4 years ago.
Why does PHP return 0 for current code? I just want to validate users name and allow to pass all letter signs available (incl. all characters like śćę......). What I'm doing wrong?
$var = 'cz -ęsc';
var_dump(preg_match('/^[\pL -]{1,35}$/', $var)); // int(0)
You need to enable Unicode for your regex, by setting the u flag, i.e.:
$var = 'cz -ęsc';
var_dump(preg_match('/^[\pL -]{1,35}$/u', $var)); // int(1)
For details, see the u (PCRE_UTF8) section in the docs: http://php.net/manual/en/reference.pcre.pattern.modifiers.php

How to replace this string with re.sub? [duplicate]

This question already has answers here:
python regular expression replacing part of a matched string
(5 answers)
Closed 4 years ago.
Assume two strings, foo.example.com/1.2.3/sdk-foo-bar.min.js and foo.example.com/1.2.3/sdk-foo-bar-dev.min.js.
By default, the first one is used in the HTML code, but depending on a parameter, I need to replace it with the second (i.e. add the -dev).
I have a regex already (foo\.example\.com/1\.2\.3/(sdk-foo-bar).min\.js) that looks for the string and captures the group sdk-foo-bar, but how can I now replace this group with sdk-foo-bar-dev??
inp = 'foo.example.com/1.2.3/sdk-foo-bar.min.js'
m = re.search('(^.*)(.min.js)', inp)
if m:
print ('%s-%s%s' % (m.group(1), 'dev', m.group(2)))

Python2.7 re fullmatch alternatives [duplicate]

This question already has answers here:
Backport Python 3.4's regular expression "fullmatch()" to Python 2
(2 answers)
Closed 5 years ago.
Is there a way to match a complete string before python3.4(as they introduced fullmatch() method here.)
For eg. If i have a string '12.345' and If i want to check for float with no exponential and i use the pattern: r'-?(?:\d+())?(?:\.\d+())?'. But this pattern also works for '12.345abc'.
How can i make re to not match second string '12.345abc'?
Thanks!
You might want to use anchors in combination with filter() and lambda():
import re
strings = ['12.345', '12.345abc']
rx = re.compile(r'^\d+(\.\d+)?$')
numbers = list(filter(lambda x: rx.match(x), strings))
print(numbers)
# ['12.345']
This makes sure no rubbish is matched afterwards.

How to convert special ereg_replace functions [duplicate]

This question already has answers here:
How can I convert ereg expressions to preg in PHP?
(4 answers)
Closed 5 years ago.
How can I convert / update the following regular expression functions to be valid in PHP 7:
$rawsub=ereg_replace("</*b>", "", $subject);
$qauthor=ereg_replace("<b>|</b>", "", $author);
$body=eregi_replace("<(mailto:)([^ >\n\t]+)>", "{phopen}a href=\"\\1\\2\"{phclose}\\2{phopen}/a{phclose}", $body);
$body=eregi_replace("<([http|news|ftp]+://[^ >\n\t]+)>", "{phopen}a href=\"\\1\"{phclose}\\1{phopen}/a{phclose}", $body);
$body=eregi_replace("<(/*($ForumAllowHTML) *[^>]*)>", "{phopen}\\1{phclose}", $body);
You can go for preg_replace() instead of using ereg_replace() and rewrite your pattern according to preg_replace(). For more details, you can visit this link below.
preg_replace()
Difference between preg_replace() and ereg_replace()