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();
Related
This question already has answers here:
Java replace all square brackets in a string
(8 answers)
Closed 4 years ago.
I am having string as below and want prefix to be removed [*TESTABC*]
String a = "[*TESTABC*]test#test.com";
Expected result: test#test.com
I tried below code but it is removing the bracklets only. I need to remove the inner content also.
The string with come in this pattern only. Please help.
String s = "[*TESTABC*]test#test.com";
String regex = "\\[|\\]";
s = s.replaceAll(regex, "");
System.out.println(s); //*TESTABC*test#test.com
int index;
String s = "[*TESTABC*]test#test.com";
index=s.indexOf(']');
s=s.substring(index+1);
System.out.println(s);
**i solve your question according to your problem and output **
This question already has answers here:
Match text between two strings with regular expression
(3 answers)
Closed 4 years ago.
there are some Japanese sentences like following:
{keyword: 部屋}いいね!
{keyword: 公園}は綺麗です.
私は{keyword: 部屋捜査}です。
..........
.........
I want to replace the substring like :{keyword: 部屋},{keyword: 公園}..... with 'keyword'.
For example:
input: 私は{keyword: 部屋捜査}です
output: 私はkeywordです
My trying code is following and but it is wrong, the result is same:
import re
s = '{keyword: 賃貸}'
t = re.sub(r"\{keyword:[あ-んア-ン一-]+\}", 'keyword', s)
print(t)
Thanks!
Use the following:-
inputString = "私は{keyword: 部屋捜査}です"
t = re.sub(r"\{keyword:[^}]*}", 'keyword', inputString)
print(t)
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 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
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.