Get regex to stop at a certain character, but include that character in match
Tag : php , By : Juan Pablo
Date : March 29 2020, 07:55 AM
it fixes the issue Right now, this regex matches something and stops at a slash ( / ), but I need it to stop at the slash and include the slash. Or in other words stop at whatever character is after the slash. But, I don't know what that charcter is. , You can do it in 2 ways : (?:https?:\/\/|www)[^\/]*\/
(?:https?:\/\/|www).*?\/
(?:https?:\/\/|www)[^\/]+(?:\S*?\/)*
|
Is there a way to stop a RegEx before a character value and start another one after that character?
Tag : java , By : mediafarm
Date : March 29 2020, 07:55 AM
wish of those help I'll first suggest two alternate approaches, then answer your question as it stands. Perhaps beter without regular expressions // Multiplication of unparenthesized integers
Pattern p = Pattern.compile("(\\d+)\\s*\\*\\s*(\\d+)");
Matcher m = p.matcher(s);
while (m.find()) {
int a = Integer.parseInt(m.group(1));
int b = Integer.parseInt(m.group(2));
s = s.substring(0, m.start(1)) + (a*b) + s.substring(m.end(2));
m.reset(s);
}
|
Using scanf for character input, but the do-while loop wont stop at the null character
Date : March 29 2020, 07:55 AM
this one helps. There aren't any nul-terminated strings here, but only string arrays. So, when pressing enter, a[i-1] is \n not \0 (scanf with %c as parameter doesn't nul-terminate the strings, and ENTER is just a non-nul character with code 10 AKA \n) #include <stdio.h>
main()
{
char a[50];
int i;
printf("Give max 50 characters\n");
i=0;
do
{
scanf("%c", &a[i]);
i=i+1;
}
while((i<sizeof(a)) && (a[i-1]!='\n')); // \n not \0
int j;
for(j=0; j<i; j++) // stop at i
printf("%c", a[j]); // output is flushed when \n is printed
}
|
PHP Remove Everything After Character and Stop Before Character
Tag : php , By : Patastroph
Date : March 29 2020, 07:55 AM
this will help Should be able to use PHP's strstr in-built function in combination with str_replace to get the result you're after $string = '/my-picture-gallery-1000x2000.jpg';
echo str_replace(strrchr($string, '-'), '', $string) . strstr($string, '.');
$string = '/my-picture-gallery-1000x2000.jpg';
$dimensions = strrchr($string, '-');
$extension = strrchr($string, '.');
$image = str_replace($dimensions, '', $string) . $extension;
|
How can I capitalize every letter after the > character and stop it when the < character is met?
Date : March 29 2020, 07:55 AM
|