Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 9 years ago.
Improve this question
In lex, I can define the following starting condition for equations defined between $...$.
%x EQN1
\$ { BEGIN(EQN1); }
<EQN1>{
\$ { BEGIN(INITIAL); }
[^\$]* {}
}
For equations between $$...$$, how can I define the anything but $$ rule, such as in [^\$]*. I guess [^\$\$]* wouldn't work.
I think you don't understand the way the patterns are matched, see flex manual
Flex always try to match longest input possible. You can understand it in way, that longer rules have higher priority.
Because "\$\$" match two characters and "." just one, the example below will work just fine.
%x EQN2
\$\$ { BEGIN(EQN2); }
<EQN2>{
\$\$ { BEGIN(INITIAL); }
. {}
}
You can also replace [^\$]* {} with . {} in your example, because when rules match same size of input, the first one in lex.l has higher priority.
Related
Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 3 years ago.
Improve this question
I am using Powershell and I have a variable like this:
$E = "Apple"
When I run $E[0] I expect to see Apple, but it shows A only. How can I do that?
$E = "Apple" Is not an array, it is a simple string declaration so when you try to get index 0 of that string (or char array) you are returning the first character in the character array:
0 1 2 3 4
[A] [P] [P] [L] [E]
The define an array you need a second item (separated by a comma):
$E = "Apple", "Orange"
Then you can use $E[0] to return Apple like you are wanting.
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 4 years ago.
Improve this question
I am extracting oracle version from windows using powershell command and i get result as 10.2.0.3.0Patch2, however i need to extract only numeric value i.e. 10.2.0.3.0 (only version number). Any way we can do it ?
Version info extracted is =
10.2.0.3.0 Production, 10.2.0.3.0Patch2 Production, 10.2.0.5.0 Production, 11.2.0.4.0 Production
You can use a regular expression to extract a substring. Example:
"10.2.0.3.0Patch2" | Select-String '((?:\d{1,3}\.){4}\d{1,3})' | ForEach-Object {
$_.Matches[0].Groups[1].Value
}
# Outputs the string '10.2.0.3.0'
You can read more about regular expressions by reading the about_Regular_Expressions help topic:
PS C:\> help about_Regular_Expressions
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 7 years ago.
Improve this question
How can I detect and show an error if someone put a letter and the program expects a number?
A regexp match makes this easy. Searching for any character which isn't a numeral or an arithmetic symbol:
if ( $input =~ /[^0-9+*/-]/ ) {
print "Incorrect character detected!\n"
}
Literally anything which is a letter:
if ( $input =~ /[A-Za-z]/ ) {
print "Incorrect character detected!\n"
}
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
Can someone explain what the second half of this script does? (second line)
$self is defined elsewhere... (I know what that part does, Just wondering what the action=~... is all about/)
$action = "http://example.com/test.php";
$action = $self->{url} . ($action =~ /^\// ? "" : "/" ) . $action;
It returns an empty string if $action starts with a slash, and a slash if it does not start with a slash.
Closed. This question is off-topic. It is not currently accepting answers.
Want to improve this question? Update the question so it's on-topic for Stack Overflow.
Closed 10 years ago.
Improve this question
I am editing a Wiki page on GitHub using the Markdown edit mode and trying to insert a block of code form a shell script as follows:
```
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u#\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi
```
However, the block ends up looking like this instead:
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[SAME-43-CHAR-SEQUENCE[01;32m\]\u#\h\[SAME-43-CHAR-SEQUENCE[00m\]:\[SAME-43-CHAR-SEQUENCE[01;34m\]\w\[SAME-43-CHAR-SEQUENCE[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi
So it looks like it's interpreting the char sequence \033 as some sort of code SAME-43-CHAR-SEQUENCE which looks like some sort of UUID. How can I avoid that? Thx
Escaping the slash with another slash seems to work.
So, change \033 to \\033
if [ "$color_prompt" = yes ]; then
PS1='${debian_chroot:+($debian_chroot)}\[\\033[01;32m\]\u#\h\[\\033[00m\]:\[\\033[01;34m\]\w\[\\033[00m\]\$ '
else
PS1='${debian_chroot:+($debian_chroot)}\u#\h:\w\$ '
fi