This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 6 years ago.
i have CUSD data like this:
"AT+CUSD=1,"*388#",15 OK +CUSD: 0,"PulsaUTAMA Rp.3375. Aktif 01/12/16, Tenggang 31/12/16,SMSHarian 0 ke ISAT& 0 SMS ke Opr lain.Eklusif Arsenal+grts tlp 1jm,hub *465*4#",64 "
How to regex to get value :
PulsaUTAMA Rp.{currency balance}
Aktif {dd/mm/yyyy}
Tenggang {dd/mm/yyyy}
Thank's
This is code from #Wiktor Stribiżew, working perfectly.
Dim s As String = "AT+CUSD=1,""*388#"",15 OK +CUSD: 0,""PulsaUTAMA Rp.3375. Aktif 01/12/16, Tenggang 31/12/16,SMSHarian 0 ke ISAT& 0 SMS ke Opr lain.Eklusif Arsenal+grts tlp 1jm,hub *465*4#"",64"
Dim p As String = "PulsaUTAMA\s+Rp\.(?<balance>\d+)\.\s*Aktif\s*(?<date1>[\d/]+),\s*Tenggang\s*(?<date2>[\d/]+)"
Dim res As Match = Regex.Match(s, p)
If res.Success Then
Console.WriteLine(res.Groups("balance").Value)
Console.WriteLine(res.Groups("date1").Value)
Console.WriteLine(res.Groups("date2").Value)
End If
Related
This question already has answers here:
Regular expression for letters, numbers and - _
(6 answers)
Difference between * and + regex
(7 answers)
Closed 4 years ago.
I want a regular expression in java which should allow alphabets,number and comma. Could anyone please help?
I am using the code. But it is not working
Pattern p = Pattern.compile("^[A-Za-z0-9,]$", Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(object.toString());
boolean bcheck = m.find();
This question already has an answer here:
Reference - What does this regex mean?
(1 answer)
Closed 4 years ago.
I would like to extract two numbers for a strings by regex "[0-9]+"
var str = "ABcDEFG12345DiFKGLSG938SDsFSd"
What I want to extract is "12345" and "938".
But I am not sure how to do so in Kotlin.
This should work:
import java.util.regex.Matcher
import java.util.regex.Pattern
fun main(args:Array<String>) {
val p = Pattern.compile("\\d+")
val m = p.matcher("ABcDEFG12345DiFKGLSG938SDsFSd")
while (m.find())
{
println(m.group())
}
}
Pattern.compile("\\d+"), it will extract the digits from the expression.
This question already has answers here:
Get values between curly braces c#
(3 answers)
Closed 7 years ago.
how to get the value between first { and last } from a string which have multiple {}.
eg string: ".....[object:{ ..{...{..}...}..}]"
My approach using C#:
line="abcd..efg..[object:{ ab{..c{d.}.e.}f....g}]"
string p = ".*\\[Object:{([A-Za-z{}]*)}\\]";
Regex r = new Regex(p);
Match m=r.match(line);
string value=m.Groups[1].Value.ToString();
Result should be:
value= ab{..c{d.}.e.}f....g
{.*}
or
(?<={).*(?=})
This should do the trick for you.See demo
string strRegex = #"{.*}";
Regex myRegex = new Regex(strRegex, RegexOptions.Multiline);
string strTargetString = #".....[object:{ ..{...{..}...}..}]";
foreach (Match myMatch in myRegex.Matches(strTargetString))
{
if (myMatch.Success)
{
// Add your code here
}
}
This question already has answers here:
How do I match any character across multiple lines in a regular expression?
(26 answers)
Closed 3 years ago.
Given a collection of strings which start all with prefix _abc_ABC( and end with suffix ), for instance,
val a = """_abc_ABC(
{
x = 1
y = 2
})"""
how to define a regular expression that strips out the prefix and suffix above ?
This would work:
val a = """_abc_ABC(
{
x = 1
y = 2
})"""
val Re = """(?s)_abc_ABC\((.*)\)""".r
a match { case Re(content) => println(content) }
The (?s) makes it match over multiple lines.
This question already has answers here:
How can I validate an email address using a regular expression?
(79 answers)
javascript email validation check condition issue
(2 answers)
Closed 9 years ago.
I am using the email validation as mentioned below :
private static final String EMAIL_PATTERN = "^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*#[A-Za- z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";
in this pattern i need (hypen, apostrophe, underscore, period) to be included.
For example - pqr.m.o'abc#xyz.com
Please suggest
You can use something like this :
^[_A-Za-z'\\.\\!'0-9-\\+]+(\\.[_A-Za-z0-9\\!\\.'-]+)*#[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})
REGEX: ^([_A-Za-z'\.\!'0-9-\\+]+(\.[_A-Za-z0-9\\!\\.'-]+)*#[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*\.[A-Za-z]{2,})$
Demo
use \. for . where \ is the escape character .
UPDATE
To remove consecutive special characters , you can use :
String ar[] ={ "pqr.m.o''abc#xyz.com","pqr.m.o'abc#xyz.com"};
String REGEX = "[_A-Za-z'\\.\\!'0-9-\\+]+(\\.[_A-Za-z0-9\\!\\.'-]+)*#[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})";
Pattern p = Pattern.compile(REGEX);
for(String theString:ar){
Matcher m = p.matcher(theString);
while (m.find()) {
String matched = m.group();
String regex = "([._!'-])\\1";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(matched);
if (!matcher.find()) {
System.out.println(matched);
}
}
}