Date : March 29 2020, 07:55 AM
will help you I basically have an array in php which contains a string, I basically need to filter the string in order to get a 9 digit ID number (which is surrounded by brackets), im sure there could be a way to do this with regex but im clueless. , by using preg_replace you just have one line filter.... $str['task'] = preg_replace('/.*\((\d{9})\).*/', '$1', "meeting mike (298124190)");
$strings = array("meeting mike (298124190)", "meeting mike (298124190)", "meeting mike (298124190)");
foreach ($strings as $string) {
if (preg_match("|\(([\d]{9})\)|", $string, $matches)) {
$str[] = $matches[1];
// OR $str['task'][] = $matches[1];
}
}
print_r($str);
|
Tag : php , By : Michael T.
Date : March 29 2020, 07:55 AM
Hope this helps Sample string , Another solution for your specific type of string: where $string = "Rpt#_SPACE_MINVTAN<br_SPACE_/>_SPACE__SPACE__SPACE__SPACE__SPACE_01212_SPACE__SPACE_";
<?php
$text = "Rpt#_SPACE_MINVTAN<br_SPACE_/>_SPACE__SPACE__SPACE__SPACE__SPACE_01212_SPACE__SPACE_";
$text_array = explode("<br_SPACE_/>", $text);
$array1 = explode("_SPACE_", $text_array[0]);
echo $array1[0] . ' and ' . $array1[1];
$number = trim($text_array[1], "__SPACE__");
echo '<br>and ' . $number;
?>
$array1[0] is the 'Rpt#'
$array1[1] is the 'MINVTAN'
$number is '01212'
|
Date : March 29 2020, 07:55 AM
will help you You may capture the value you need into a capturing group and access it with the corresponding code. The regex for both Java and Python can look like postgresql://[\d.]+:(\d+)\b
String s = "Install: C:\\Program Files\\app\nDatabase: postgresql://127.0.0.1:42018/app\nStarted: 2016-12-28 10:40:05.908000\nLines: 1000000\nVersion: 4.1\nPID: 1736";
Pattern pattern = Pattern.compile("postgresql://[\\d.]+:(\\d+)\\b");
Matcher matcher = pattern.matcher(s);
if (matcher.find()){
System.out.println(matcher.group(1));
}
import re
s = "Install: C:\\Program Files\\app\nDatabase: postgresql://127.0.0.1:42018/app\nStarted: 2016-12-28 10:40:05.908000\nLines: 1000000\nVersion: 4.1\nPID: 1736";
pattern = r"postgresql://[\d.]+:(\d+)\b"
m = re.search(pattern, s)
if m:
print(m.group(1))
|
How to extract only 6 digit number from a random String message? 6 digit number is not in the beginning or end of the me
Tag : java , By : FuzzyHornet
Date : March 29 2020, 07:55 AM
will help you You can extract any 6 digit number from any String message. "|" is used to lookup more possible combinations. Only "\d{6}" also give you the correct result for your problem. //find any 6 digit number
Pattern mPattern = Pattern.compile("(|^)\\d{6}");
if(message!=null) {
Matcher mMatcher = mPattern.matcher(message);
if(mMatcher.find()) {
String otp = mMatcher.group(0);
Log.i(TAG,"Final OTP: "+ otp);
}else {
//something went wrong
Log.e(TAG,"Failed to extract the OTP!! ");
}
}
|
Tag : sql , By : tanminivan
Date : March 29 2020, 07:55 AM
I wish this help you I have two input strings that look like 'London 350 Paris 456 eu iu' and 'New York 154 Seattle 890 pc appl iu'. , In this way you can get the First number. DECLARE @VAR VARCHAR(MAX) = 'London 350 Paris 456 eu iu'
SELECT SUBSTRING(@VAR, PATINDEX('%[0-9]%', @VAR), PATINDEX('%[^0-9]%', SUBSTRING(@VAR, PATINDEX('%[0-9]%', @VAR), 100)))
|