How to convert special ereg_replace functions [duplicate] - regex

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()

Related

RegExp for Hangul in Ruby [duplicate]

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)) // ["안", "녕"]

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)))

I have two regex in .net preRegex = "(?<=(^|[^A-Za-z0-9]+))" postRegex = "(?=([^A-Za-z0-9]+)|$)" . What is the alternate of it in python? [duplicate]

This question already has answers here:
Python Regex Engine - "look-behind requires fixed-width pattern" Error
(3 answers)
Closed 5 years ago.
I have two regex strings in .net
preRegex = "(?<=(^|[^A-Za-z0-9]+))"
postRegex = "(?=([^A-Za-z0-9]+)|$)"
I want their alternative in python. My problem is let say I have a string
s="I am in aeroplane."
What I need is to replace "aeroplane with aeroPlain" so I want to make regex like
newKey = preRegex + aeroplane + postRegex
pattern = re.compile(newKey,re.IGNORECASE)
new regex string look like
(?<=(^|[^A-Za-z0-9]+))aeroplane(?=([^A-Za-z0-9]+)|$)
but it is giving me error "look-behind requires fixed-width pattern".
I am new to python, Help would be appreciated. Thanks
You can use the following regex:
(^|[^A-Za-z0-9]+)aeroplane([^A-Za-z0-9]+|$)
and when you replace, you can call the back reference to the first and second part of your regex to fetch their value.
Replacement string will be something like '\1aeroPlain\2'.
For more information on backref in python:https://docs.python.org/3/howto/regex.html
Good luck!

vb.net regex - capture text between comms [duplicate]

This question already has answers here:
Splitting a string on comma and printing the results
(3 answers)
Closed 6 years ago.
I am trying to extract the first three columns from these two lines of text.
A,Frequency,1.005 kHz,1.005 kHz,1.005 kHz,1.005 kHz,94.75 mHz,20,WholeTrace,
A,True RMS,1.404 V,1.403 V,1.404 V,1.403 V,232.6 æV,20,WholeTrace,
So what I would like displayed (extracted) form the above string is:
1.005 kHz
1.404 V
I found this post Regex exclusive capture between strings (VB.NET)
Which is seemingly doing something very similar, so I tried to modify that regex, however I am failing dismally (not least of all because I am really struggling to understand regular expressions!).
For mine, I tried
cy,\s+(\d+)\s+Hz\s+
But that doesn't work.
Could someone kindly help please?
This is in vb.net (VS 2013)
Using a Split function:
Dim value As String = Split("A,Frequency,1.005 kHz,1.005 kHz,1.005 kHz,1.005 kHz,94.75 mHz,20,WholeTrace,", ",")(2)

Drop values between two characters in a string [duplicate]

This question already has answers here:
get filename from url path in R
(2 answers)
Closed 7 years ago.
Suppose I have multiple forms of the following string
x <- "/Users/name/Google Drive/Thesis/Data/Data X and Y/UK//5port/5groups.csv"
I want to drop the values between the first / and the last / to return only 5groups.csv. I used gsub but couldn't find how to specify that pattern.
My question is the same like this one but in R.
If we are using sub
sub('.*\\/', '', x)
#[1] "5groups.csv"