Stack Exchange Network

Stack Exchange network consists of 175 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

Questions tagged [regular-expressions]

For questions about the function RegularExpression which is used in string patterns in functions as StringCases, StringReplace, StringPosition,StringCount etc.

5
votes
3answers
73 views

StartOfLine and EndOfLine not working well inside Shortest

Suppose that I want to replace lines containing "b" with a new "XXX" line. This works as expected with regular expressions: ...
0
votes
1answer
71 views

RepeatedReplace (//.) not working as expected within an expression in a graph

I'm plotting a tangent line to a region and, depending when I evaluate it, I get inconsistent results. I want to use the first way of doing things for flexibility but it doesn't seem to be working. ...
2
votes
1answer
55 views

How to refer to a character group without ambiguity in a regex?

Suppose I want to realize a replacement in a string: "aabbcc11dd ee" -> "aabbcc112dd ee", I can use a regex like this within ...
0
votes
1answer
73 views

Evaluate until a regexp match is satisfied

How do you express the computation that, given a list of regular expressions, perform a replacement until one of them is satisfied. For instance: ...
7
votes
0answers
97 views

Mathematica lexer: Numbers

This is a follow-up question to Mathematica lexer: Symbols and UTF-8 and this it is about numbers. In Mathematica, we have a large number of ways to input numbers. They can contain a notation for the ...
3
votes
1answer
33 views

StringExpression inconsistency using Alternative

Preface: This will turn out to be a bad case of brain-malfunction. In any case, the precedence is surprising and I haven't checked the FullForm... the one thing we ...
11
votes
0answers
128 views

Mathematica lexer: Symbols and UTF-8

Did you ever wonder why here on our site, there is a highlighting difference between f[argX_] := 1; and f[argα_] := 1; ...
9
votes
4answers
1k views

How to convert a string having nested parentheses into an expression?

I am a Wolfram Language/Mathematica beginner and trying to convert STEP ISO10303 commands into geometrical regions. A simple command looks like ...
2
votes
2answers
48 views

Getting line number based on regexp match or Importing data with variable header size

I have a text file with structure: ...
5
votes
1answer
297 views

Use cases to select subelements by Regex

I have a nested list and would like to select a sub set of lists using a RegEx and I would prefer to use patterns (mainly for readability). ...
1
vote
2answers
211 views

regex to find \n within quotes and not ones outside quotes

For example, string = "ads, 32, dv, \"sdf\" sd, 213, as, \"asd asd\" asd, 123 sd, \"asd\""; There are 3 line returns \n....
8
votes
1answer
308 views

RegularExpression no longer working in Mathematica 10.4

There is a regular expression that I used often in Mathematica 8, made to locate matching curly braces: RegularExpression["(?P<0>{([^{}]|(?P>0))*})"] ...
7
votes
4answers
406 views

RegEx replacement with backreference followed by a numeric literal

I have a text file which contains lines of the type: SYMATTR InstName U1 where "1" can be actually a number with 1 to 3 digits. I want to replace the above line with the following 2 lines: ...
5
votes
2answers
73 views

How to match numbers to alphabets with period and space,

ToCharacterCode["ABCD...XYZ"] - 64 I know that I can make a list of alphabets in this way. However, I need to assign " " and <...
5
votes
1answer
94 views

Regex named groups — how to refer back to them in the replacement string [duplicate]

We can use group numbers to reuse the same piece of code while inside regex string, like that: StringCases["x = y", RegularExpression["([\\w\\s]+)=(?1)"]] <...
21
votes
1answer
542 views

Why Except is so slow as compared to equivalent RegularExpression?

When comparing performance of the solutions suggested for this question I discovered that StringExpression involving Except is ...
4
votes
3answers
224 views

Extract substring up to specific character non-inclusive

I was wondering if there is a way with StringCases to start at the beginning of a string and stop one character before a known character. ...
6
votes
3answers
157 views

dictionary lookups of words composed of specified characters

I am trying to find all English words composed of specified characters. For example, all words composed of one or more of the following: ...
0
votes
1answer
82 views

How to fix this issue with storing an expression as a String and returning it with ToExpression

( Update: Note the "." in the expression, this is most likely what causes the problem. )** Starting point of my question is the following code, which works as expected: ...
5
votes
1answer
148 views

How to iterate over a list using a Regex

I need to replace all "Nx" with "N0x" in the following, but I can't seem to figure it out. ...
9
votes
4answers
1k views

How to get the longest bracket pairs from a string

In C#, we can use regular expression to do some balancing groups, like we can get {<aa <bbb> <bbb> aa>, <<dfa>a>} from ...
13
votes
1answer
114 views

What types of string patterns can't be translated into regexes and hence do not work?

In a comment to related question Oleksandr R. made an interesting remark: ... because string patterns are converted into regular expressions and matched using PCRE, they are subject to some ...
9
votes
1answer
109 views

Can we use named references on the RHS in StringReplace?

In this great answer WReach demonstrated some advantages of usage of Named Patterns inside of RegularExpression and described the supported syntax: PCRE in ...
0
votes
2answers
92 views

Can I use StringExpression or RegularExpression to manipulate Symbolic XML?

Please, consider an XML document containing these fields: ...
21
votes
2answers
571 views

Shell Emulation inside Mathematica

I am trying to create a Mathematica/shell syntax hybrid. I would like the following command wget -qO- "http://google.com/space line break\"" $var to be ...
4
votes
1answer
109 views

Extracting integers from a string

Imagine I have a block of text that contains words and numbers. I want to extract all the integers from the text. Thus, if the input is ...
21
votes
1answer
288 views

Can Mathematica convert a RegularExpression into a StringExpression or vice-versa?

I know that Mathematica can perform string comparison using either StringExpression or RegularExpression. Although regular ...
2
votes
2answers
84 views

Date Conversion Using Regular Expressions on “Incomplete” Date Formats

I have a list of dates in one of the following formats: "1999/05/12", "1999/05/", "1999//", "****//**/", "" so that a list of such dates might appear as ...
3
votes
2answers
600 views

How remove specified substring and everything after it to the end of a string?

If I have, say, the string, txt = "now is the time for all (good) men" then I want to remove the substring beginning with "for" and ending at the end of the ...
0
votes
1answer
42 views

Regular expression help for arecord command output

How do I get the card number and device number alone from this string by using a regular expression to parse it? Here's the string ...
4
votes
2answers
224 views

Using parenthesized Regex backreferences in StringReplace

(I am sorry for my poor English,I'll try to use a simple sentence to convey me.) I can use StringCases to get the target to change like this ...
3
votes
0answers
79 views

Error importing MBOX file

I am trying to import the mbox file generated by gmail. Using the Import command. ...
2
votes
1answer
113 views

Associations - getting values according to a key pattern

I want to get all counts of trigrams that with "th" (or any other given digram). ...
3
votes
2answers
324 views

Please help translate regular expression to StringExpression

I am familiar with regular expressions in other languages (e.g., Perl, Python, ViM), but the Mathematica StringExpression is baffling me. I'd like to match strings ...
1
vote
1answer
97 views

Are all of the numbers in my file legitimate hex numbers

I have about 10,000 hexadecimal numbers (32 digits each) in an excel file, in one column. I want to verify that all of them are indeed hexadecimal number and that no other characters are present. My ...
12
votes
2answers
333 views

Convert recursive RegularExpression to StringExpression?

Consider the following expression for matching balanced brackets: ...
13
votes
3answers
431 views

Does RegularExpression support “(?R)”?

Mathematica's RegularExpression is based on Perl's PCRE library, which supports recursive regular expressions using (?R) (or, ...
2
votes
2answers
620 views

how to extract the string using regular expressions

I have the list : a1 = {"struct name1 {","struct name2{","struct name3{","struct name4{", "struct name5{","struct lastStruct{"} I tried to extract the ...
2
votes
1answer
150 views

Regular Expression - for html objects

I did a previous research about similar questions, but I really am confuse about using html objects. I have the following situation: I Import a html from a url and I need to pick the numbers that ...
0
votes
1answer
175 views

What does the expression “Total[funca[a,#] & /@ #] & /@ {x,y}” possibly mean?

Can the expression be simplified as "Total[funca[a,#]] & /@ {x,y}"? What does the double of "& /@" mean? Where can I find some reference? Updated According to Mr.Wizard's answer, I now know ...
1
vote
2answers
159 views

text analysis: split document in seperated lines

For a text analysis I want to split a large document in seperated lines. Then I want to calculated for example the average number of words. A example of the document is the following: ...
2
votes
2answers
70 views

Retain or delete parts of textstring in tweets

For a twitter analysis I collected many tweets. For example: ...
7
votes
2answers
1k views

Find file names in directory

I am trying to find the list of any file in any directory of a given name (by in the directory, I mean directly in the directory, so in a directory which is in the directory would not count). For the ...
3
votes
1answer
82 views

Convert an expression's symbols of form a$x to a[x]

I want a function that takes expressions of the following form: a$x and converts them to a[x]. In particular, consider the ...
2
votes
1answer
93 views

StringExpression: pattern reapeted one or more times matches pattern repeated zero times

I try to construct patterns using Riffle and Except StringExpression@Riffle[{"a", "b", "c"}, Except[{"=", ","}] ..] and expect it to match "a_b_c", but not "a_bc"...
3
votes
3answers
224 views

StringCases using RegularExpression fails when there is missing data

I got some text scraps with this structure "Focal Plane: 198' Active Aid to Navigation: Yes *Latitude: 35.250 N *Longitude: -75.529 W" But some of them lack ...
10
votes
1answer
498 views

Wikipedia People only search

I am trying to search people from Wikipedia(For example .*John.* in REGEX). The following query is close, but it isn't generalized like ...
3
votes
2answers
155 views

Mathematica regex equvalent of \l

In normal RegEx \l will make the character to the right lowercase. However, it seems like the RegEx in Mathematica does not have this functionality. For example <...
2
votes
1answer
103 views

Make MyLogicalExpand

The function by Mathematica to expand a formulation with ANDS, ORS, NOT, XOR, and others, is LogicalExpand, let see an example: ...
3
votes
1answer
1k views

Extract date from a not well-formed string

Is there a way to robustly extract date and time from a text? Say for example: ...The event will be held on 17/10/2013 at 3:30 PM in the room 121 and everyone is welcome... should return: ...