How to match a non-empty string - javacc

For a Token of a lexer, I want it to match a non-empty string (the string cannot contain space or new line character). The closest solution I managed to get is (~["\r","\n"," "])+. But I also want it not to contain \r\n. Is there any way to add the extra condition to my current solution?

Related

Symfony AsciiSlugger remove first special character in a string

I have a question about the string component. I am trying to create a download link using HeaderUtils::makeDisposition. I wanted to remove all special characters from the filename using AsciiSlugger. Unfortunately, if such a character is in the first position, it is removed
If the name contains only special characters, the function returns an empty string.
$response->headers->set('Content-Disposition',
HeaderUtils::makeDisposition(
HeaderUtils::DISPOSITION_ATTACHMENT,
(new AsciiSlugger('de'))->slug('äffgößdfö')
)
);
And I expected, that from (new AsciiSlugger('de'))->slug('äffgößdfö') I become aeffgoessdfoe not ffgoessdfoe.
Does anyone know how to prevent this behaviour?

How to extract a substring from main string starting from valid uuid using lua

I have a main string as below
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
From the main string i need to extract a substring starting from the uuid part
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
I tried
string.match("/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/", "/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}/(.)/(.)/$"
But noluck.
if you want to obtain
"/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
from
"/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
or let's say 7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0, output and 9999.317528060546245771146821638997525068657 as this is what your pattern attempt suggests. Otherwise leave out the parenthesis in the following solution.
You can use a pattern like this:
local text = "/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(text:match("/([%x%-]+)/([^/]+)/([^/]+)"))
"/([^/]+)/" captures at least one non-slash-character between two slashs.
On your attempt:
You cannot give counts like {4} in a string pattern.
You have to escape - with % as it is a magic character.
(.) would only capture a single character.
Please read the Lua manual to find out what you did wrong and how to use string patterns properly.
Try also the code
s="/tmp/xjtscpdownload/7eb17cc6-b3c9-4ebd-945b-c0e0656a33f0/output/9999.317528060546245771146821638997525068657/"
print(s:match("/.-/.-(/.+)$"))
It skips the first two "fields" by using a non-greedy match.

Expression for finding an index in an array

How can I find the first character in a string that is the space character and return its index, with a single expression that can be used as part of Contract_Cases?
For example, if the string is:
Input : constant String := "abc def";
then the expression should return 4.
The question originally asked for the first non-blank character in the string, for which you need Ada.Strings.Fixed.Index_Non_Blank (ARM A.4.3(12) and (61)).
As amended (the first blank character in the string), use Ada.Strings.Fixed.Index - see the OP’s comment below.

How to get a count of number of occurrence of a substring in a string in teradata?

I have a column in a teradata table with string values like "page1-->page2-->page1-->page3-->page1--page2-->..."
I want to search for a specific page and get the number of occurrence of the page in the string. I couldn't find any function that gives this result.
There's no builtin function, but there's a common solution:
Remove all occurences of the substring from the string and compare the length before/after:
(Char_Length(string) - Char_Length(OReplace(string, searchstr))) / Char_Length(searchstr)
Edit:
For a wildcard search you can utilize REGEXP_REPLACE:
Char_Length(RegExp_Replace(RegExp_Replace(s, 'page1(.+?)page3', '#',1,0), '[^#]','',1,0))
For `#' use a character which is known not to be in your input string.

Regex: Capture only numbers with a X-XXXXX-XXXXX pattern (Skip unwanted characters)?

I have a number of 0-12345-67890 and I want to capture 0123456789 in a named capture group. I got this far:
#"(?<upc>\d-\d{5}-\d{5})"
Which captures the string as-is. How do you skip the dashes while grabbing the number as a single named group? BTW, this is ASP.NET Regex.
I don't believe you can do this with a regex match to a single backreference. Either you match the dashes, or you don't (and capture nothing).
You'll have to remove them manually with Replace() after capturing the numbers:
var number = m.Groups["upc"].Replace("-", "");
You don't. You either capture in 3 groups and concatenate them into a single string, or do a search-and-replace to get rid of the dashes in your single named group.

Resources