Stack Exchange Network
Stack Exchange network consists of 181 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.
Visit Stack Exchange
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this community
Anybody can ask a question
The best answers are voted up and rise to the top
I want to copy a section of a string, which lies between two fixed string sections. How to do it?
For example if the string is "...\abcd124\145@cvdf\efgh...". How to tell Mathematica to copy the number between abcd124\ and @cvdf, which is 145.
Here "..." means that the string continues on both sides, but may be different for each case.
asked Aug 2, 2021 at 8:24
1,10355 silver badges99 bronze badges
- Split the string on the backslash
- Find the part that ends with
- Take the digits and convert to an expression, then use
FromDigits to get the final number.
str = "...\\abcd124\\145@cvdf\\efgh...";
SelectFirst[StringSplit[str, "\\"], StringEndsQ[#, "@cvdf"] &],
answered Aug 2, 2021 at 9:37
22.8k22 gold badges1616 silver badges7979 bronze badges
To find a numeric value between the strings "abcd124\" and "@cvdf", we can use a named pattern and
StringCases. Assume the pattern happens only once within
string = "\\abcd124\\145@cvdf\\efgh";
Get the same result using
RegularExpression with this expression:
answered Aug 2, 2021 at 10:36
4,21422 gold badges1515 silver badges2626 bronze badges