Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 days ago.
Improve this question
I am using XMPie and need a regex to character count for me. My Regex is ^[\S\s]{1,800}$ but I am getting a different result with the refresh preview button than the next screen button. I had a support case on it and it went all the way to R&D and they basically said, there is nothing we can do, try a different expression. I think one button must be implemented with C# and the other with JS or some such thing. What seems to be happening is that one is counting a return once (refresh), while the other is counting 2 characters for it. I think it must see it as \r or \n and count that as 2. Any ideas on how I could modify my expression to prevent that? I mostly just want consistency, so making it explicitly count it twice, or not count it at all would be more livable than differing results, especially as refresh is lower.
Thanks so much for any help!
I have tried a slew of different expressions, but I am not great with regex and nothing has given me a better result.
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 3 years ago.
Improve this question
I have implemented a multi-map, but I was wondering how do I access the first 5 elements of a multimap?
I tried using a for-loop, but that didn't work out. Any suggestions?
Although it would be easier to help you if you were to post a minimal reproducible example, as text, formatted as a code sample, I think I still understand what you’re asking.
This looks like a learning exercise that you want to solve on your own. But I can give some advice.
What you want to do is check two conditions: that you’ve read five elements, or that you’ve run out of them. Declare both a loop counter initialized to 0 and an iterator.initialized to .begin(). Loop until the counter is equal to 5 or the iterator is equal to .end(). On each iteration, increment both the counter and the iterator. You might express this as a while loop, but you could also do it with comma operators in your for loop.
Also, please indent your code properly and use braces under your for and if statements. It’ll save you from writing a lot of bugs and make your code much easier to read.
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
I have a variable that looks like this: AF1400006
I want to use regular expressions in order to return the number "14000".
I have gone through many threads here, but none quite seems to get me anywhere.
Thanks!
EDIT:
I don't see what's up with the downvotes, isn't this a forum for asking questions?
Anyhow, I solved my problem now, thanks for the help :-) For those wondering, I used it in a scanning software called Drivve Image to use parts of a barcode on a document as the name of the output folder. The software uses a unique regex formatting which seemed to be my issue.
You would need to use something like \d{5} which will match 5 digits.
Depending on the language you are using you would then access whatever the group matched.
For instance, in Java:
String str ="AF1400006";
Pattern p = Pattern.compile("\\d{5}");
Matcher m = p.matcher(str);
if(m.find())
System.out.println(m.group());
Which yields the number you are after.
An example of the expression is available here.
Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
This question does not appear to be about programming within the scope defined in the help center.
Closed 9 years ago.
Improve this question
I am struggling with a homework problem. I have tried this problem for hours literally. I found a similar question here, but it is not exactly my problem.
The homework problem says 1. (20 points) Construct regular expressions for the following languages.
a) All strings of digits with at most one repeated digit.
The only way I see how this is possible would be to exhaustively somehow take care of every possible case. There are 10 different digits, so it's like A LOT of different cases. I think the max length string can be 11, because after 11, you have to have a second repeated digit. So the number of possible combinations is 10^11. I thought even about writing a DFA and just converting it to a regex, but even that seems like it's impossible.
Does anyone have any advice? We aren't allowed to use non-standard regex features, like groups, lookahead, etc. This is just a plain old regex kind of problem.
Response to comment:
It is not binary. I already asked the teacher.
"Commenters, “regular expression” has one well-defined meaning in computer science. Since this is homework, it’s almost certainly that which is meant (and even more so as it talks of “languages”), and not some specific library. There’s no ambiguity here, and no clarification needed." This is basically what we want. The standard regex stuff often used in theoretical CS classes. As far as what we learned in class, I go to USC if anyone is familiar with that and we only barely talked about this at all. We're onto a completely different topic now.
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 8 years ago.
Improve this question
So I want to search for A,B,C,D in a string in any order, but if C doesn't exist I still want it to give me A,B, and D, etc.
To be more specific, here is the exact problem I'm trying to solve. CSV file with lines that look like this:
Name,(W)5555555,(H)5555555,(M)5555555,(P)5555555
However, the W,H,M,P could be in any order. Plus they don't all exist on every line. So it looks more like this:
Name,(W)5555555,(H)5555555,(M)5555555,(P)5555555
Name,(H)5555555,(P)5555555,(W)5555555,(M)5555555
Name,(M)5555555,(H)5555555,,
Name,(P)5555555,,,
What I need to accomplish is to put all items in the correct order so they line up under the correct columns. So the above should look like this when I'm done:
Name,(W)5555555,(H)5555555,(M)5555555,(P)5555555
Name,(W)5555555,(H)5555555,(M)5555555,(P)5555555
Name,,(H)5555555,(M)5555555,
Name,,,,(P)5555555
Edit: It appears I'm a bad Stack Overflow citizen. I didn't get answers fast enough for when my project needed to be done, and therefore forgot to come back and add a correct issues in my post. I ended up writing a python script to do this instead of just using find/replace in BBEdit or Sublime Text 2 like I was originally trying to do.
So I would like a method to do something like this that works in either BBEdit or Sublime Text. Or Vim for that matter. I'll try to keep a better eye on it this time, and I'll respond to the answers that already exist.
If your regex flavor supports lookarounds, this can be done with a simple regex-replace. Since lookaheads do not advance the position of the regex engine's cursor, we can use them to look for multiple patterns somewhere after one particular position. We can capture all these findings and write them back in the replacement string. To make sure that all of them are optional we could simply use ?, but in this case, I'll add an empty alternative to the lookahead - this is necessary to trick the engine when it's backtracking. The pattern could then look like this:
^Name,(?=.*([(]W[)]\d+)|)(?=.*([(]H[)]\d+)|)(?=.*([(]M[)]\d+)|)(?=.*([(]P[)]\d+)|).*
The .* at the end is to make sure that everything gets removed in the replacement.
And the replacement string like this:
Name,$1,$2,$3,$4
Here is a working demo using the ECMAScript flavor. It's a rather limited flavor, so this solution should be adaptable to most environments.
Something like this?
^Name,(\((?:W|H|P|M)\)\d+(?:,)?)*[,]*$
Edit live on Debuggex
Will give you all the matches per row. Then you simple need to allocate each match to the right column.
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 9 years ago.
Improve this question
I saw somewhere that a regex can be used as an input method, is this possible? How?
I really don't know anything else about that, I supposed that there's a way to procude Strings from a regex and feed an object with that String, again, this is only what I pictured and I don't know if it's even possible.
EDIT
I know I didn't explain myself, I was in a hurry, sorry for that. Well, long story short. Last week I saw an article about regex, and in one paragraph said "regex could be used as input", thats all it said about that, I couldn't find the article again so I think I could ask here.
Thanks for the votes down. Next time I'll make sure to explain correctly my doubts and to not piss someone off...
A regular expression is not an "input method". A regular expression can be used to constrain input though.
A regex can be input, if your users are the sort that live, eat, and breathe regexps (I can't imagine who would do so...), but even so, that regexp won't become the method.
Since a regex is just a string, it is techniclaly possible to use it as either:
a user input to a program (not often, but I hav seen some applications accept them, usually as a form of "advanced" search filtering)
an input parameter to a method call which accepts a string.
Perhaps one of these is the answer you are looking for?