Viewed   93 times

A column in my spreadsheet contains data like this:

5020203010101/FIS/CASH FUND/SBG091241212

I need to extract the last part of string after forwward slash (/) i.e; SBG091241212

I tried the following regular expression but it does not seem to work:

/.*$

Any Idea?

 Answers

5

You need to specify a matching group using brackets in order to extract content.

preg_match("//([^/]+)$/", "5020203010101/FIS/CASH FUND/SBG091241212", $matches);

echo $matches[1];
Wednesday, October 26, 2022
 
skiwi
 
5
$res=substr($input,0,strrpos($input,':'));

I should probably highlight that strrpos not strpos finds last occurrence of a substring in given string

Monday, November 14, 2022
 
5

The Arabic regex is:

[u0600-u06FF]

Actually, ?-? is a subset of this Arabic range, so I think you can remove them from the pattern.

So, in JS it will be

/^[a-z0-9+,()/'su0600-u06FF-]+$/i

See regex demo

Tuesday, October 11, 2022
5

Put more simply than the other examples:

function some_function($path,$base){
  $baselen = strlen($base);
  if (strpos($path,$base) === 0 && strlen($path)>$baselen)
    return substr($path,$baselen);
  return false;
}

DEMO

Alternate using strncmp, too: DEMO

Wednesday, August 24, 2022
3

For this PHP regex:

$str = preg_replace ( '{(.)1+}', '$1', $str );
$str = preg_replace ( '{[ '-_()]}', '', $str )

In Java:

str = str.replaceAll("(.)\1+", "$1");
str = str.replaceAll("[ '-_\(\)]", "");

I suggest you to provide your input and expected output then you will get better answers on how it can be done in PHP and/or Java.

Sunday, October 9, 2022
 
haodong
 
Only authorized users can answer the search term. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :