Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
What's the PHP ereg() equivalent in Visual Basic .NET?
I'm trying to translate this tripcode encoder from PHP to VB.NET
function tripcode($name)
{
if(ereg("(#|!)(.*)", $name, $matches))
{
$cap = $matches[2];
$cap = strtr($cap,"&", "&");
$cap = strtr($cap,",", ",");
$salt = substr($cap."H.",1,2);
$salt = ereg_replace("[^\.-z]",".",$salt);
$salt = strtr($salt,":;<=>?#[\\]^_`","ABCDEFGabcdef");
return "!".substr(crypt($cap,$salt),-10)."";
}
}
$Str = "#your_tripcode_password"
Dim Reg As New Regex("(#|!)(.*)")
If Reg.IsMatch(Str) Then
Dim Cap$ = Reg.Matches(Str)(0).Groups(2).Value
End If
Related
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 1 year ago.
Improve this question
How can I get from string "C27_W112_V113_Table__6__1" string "6" or from string "C27_W120_V153_Table__22__1" string "22". thx
You can achieve it by two ways
Regex approach:
const re = /(\d+)__\d+$/;
let values = [
'C27_W112_V113_Table__6__1',
'C27_W120_V153_Table__22__1'
];
values.forEach(str => console.log(str.match(re)[1]));
string manipulation (I assume the value is always at the same place):
values.forEach(str => {
let reversed = str.split('').reverse().join('');
let index = reversed.indexOf('__');
console.log(reversed.slice(index+2, reversed.indexOf('__', index+1)));
});
Here a snippet
const re = /(\d+)__\d+$/;
let values = [
'C27_W112_V113_Table__6__1',
'C27_W120_V153_Table__22__1'
];
values.forEach(str => console.log(str.match(re)[1]));
console.log('--------');
values.forEach(str => {
let reversed = str.split('').reverse().join('');
let index = reversed.indexOf('__');
console.log(reversed.slice(index+2, reversed.indexOf('__', index+1)));
});
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I have the below format of a string:
str1 = "a, b, c, d, e";
str2 = "aa, ba, ca, da, essd";
str2 = "aass, bsda, cads, dsda, esssdsd";
I want to extract the end of the string after splitting --> e, essd, esssdsd.
Assuming these are std::strings, I'd use rfind to find the last occurrence of the delimiter, and then take a substring from there. E.g.:
size_t index = str.rfind(", ");
string last_element = str.substr(index + 2); // 2 is the size of the delimiter
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 5 years ago.
Improve this question
I would like to use string class, to extract some information from the string.
Given the string: <12,Apple>,<20,Orange>,<49,iPhone>
I would like to let 12, 20, 49 to a int array.
that means a[0] = 12, a[1] = 20, a[2] = 49.
And let Apple, Orange, iPhone to a String array.
that means b[0] = "Apple", b[1] = "Orange" b[2] = "iPhone"
How should I do?
Assume the string follows the format <int,string>,.... Please find the pseudo-code below:
Loop through the string `str` and
{
smaller_sign_pos = str.find('<', prev_pos)
entry_comma_pos = str.find(',', smaller_sign_pos+1)
greater_sign_pos = str.find('>', entry_comma_pos+1)
if (all pos values are not `npos`)
{
int_value = atoi(str.substr(smaller_sign_pos+1, entry_comma_pos-smaller_sign_pos-1))
str_value = str.substr(entry_comma_pos+1, greater_sign_pos-entry_comma_pos-1)
prev_pos = greater_sign_pos+1
append int_value to int array
append str_value to string array
optional: you can check if the comma after '>' exists
}
else
{
break or set the end of loop flag
}
}
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I'm looking for an regex that returns everything after pid- in this example URL.
URL:
www.example.com/bla-pid-123456
Expected match:
123456
Using PCRE-Compatible Grep
$ echo 'www.example.com/bla-pid-123456' | pcregrep -o 'pid-\K\d+'
123456
>>> import re
>>> pat = re.compile('pid-(\d+)$')
>>> m = pat.search('www.example.com/bla-pid-123456')
>>> m.groups()[0]
'123456'
you could do it like this: (in swift because i don't know which language you use):
func findStringAfterFirstOccurenceOfString(stringToFind: NSString, inString stringToSearch: NSString) -> NSString?
for (var i = 0, i <= stringToSearch.length - stringToFind.length; i++) {
let range = NSMakeRange(i, stringToFind.length)
let sub = stringToSearch.substringWithRange(range)
if sub == stringToFind {
return stringToSearch.substringFromIndex(i + stringToFind.length)
}
}
return nil // No occurrence found
}
stringToFind would be "pid-" in this case.
try this
var result = 'www.example.com/bla-pid-123456'.match(/.*pid-(\d+)/);
result = (result) ? result[1] : "";
Since I don't know if you can acccept alpha and/or numberic after the PID, I have this. mileage may vary.
in javascript
just for alphanumberic:
var str = "www.example.com/bla-pid-123456",
re = /pid[-](\w+)$/ ,
val = str.match(re) ? str.match(re)[1] : null;
note: I explicitly capture ONLY if its "pid-.....", otherwise I assign null to "val". This is a bit more what you might need, but since I do not know your intent, and the url can have 'gig-asdfasdf', or 'whatever-whater'... I want something explicit.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
I have a String like this
String s1="1 AND 1 OR 1";
I want split with AND OR and my result should be 1,1,1
I am using JAVA /eclipse
package com.test;
String s1="1 AND 1 OR 1";
String[] splits=s1.split("[AND\OR]");
for (int i = 0; i < splits.length; i++) {
System.out.println(splits[i]);
}
}
}
Can I get any help how to do this?
Any Help appreciated
I am unsure about the language, but for C# you can use the following:
string s1 = "1 AND 1 OR 1";
string s2 = s1.Replace("AND", ",").Replace("OR", ",");
Console.WriteLine(s2);
Which doesn't use regular expressions.
If you want an array, you can use the following:
string s1 = "1 AND 1 OR 1";
string[] s2 = Regex.Split(s1.Replace(" ", string.Empty), "AND|OR");
In Java you can replace using the same mechanism:
String s1 = "1 AND 1 OR 1";
String s2 = s1.replace("AND", ",").replace("OR", ",");
System.out.println(s2);
And to get an array:
String s1="1 AND 1 OR 1";
String[] s2 = s1.replace(" ", "").split("AND|OR");