## Regex expression

Let L be the language over the alphabet {0, 1, 2, 3, (,), +, -, *, /}, L is the set of operations with correctly formatted natural numbers (a single number is considered to belong to L, 2 – – 3 is an incorrect expression, 2 + 3 is correct, 2 + (-3) is correct. Is it possible to write a regular expression for this language? If not, why?

I think that it is not possible to write a regular expression for this language, because of the operator / we not write 2 / 0 for exemple and are more than a finite number combinations to make this possible. It is correct so?

Tengo una cadena que me llega en JSON con unos datos como estos

{“name”:”AMD”,”history”:{“2019-09-05”:{“open”:”31.79″,”close”:”31.50″,”high”:”32.05″,”low”:”31.12″,”volume”:”57693493″},”2019-09-04″:{“open”:”31.32″,”close”:”30.95″,”high”:”31.83″,”low”:”30.85″,”volume”:”46709780″},”2019-09-03″:{“open”:”30.83″,”close”:”30.90″,”high”:”31.14″,”low”:”30.68″,”volume”:”38080254″}, … etc

usando

 string[] cotizacion = Regex.Split(cadena_url, @"\d{4}\-\d{2}\-\d{2}"); 

Me genera correctamente un elemento en el array cotizacion por cada dia, el problema es que el split elimina la fecha y a mi me interesa que se mantenga la fecha y la añada al array.

No consigo añadir la fecha al array.

Muchas gracias por la ayuda.

## apt-file regex: find multiple packages at once using or

I’d like to search multiple packages at one using a regexp connecting pattern with logical or |.

Assuming the two files /usr/lib/apache2/modules/httpd.exp and /usr/lib/apt/apt.systemd.daily exist:

> sudo dpkg -S /usr/lib/apache2/modules/httpd.exp apache2-bin: /usr/lib/apache2/modules/httpd.exp > sudo dpkg -S /usr/lib/apt/apt.systemd.daily apt: /usr/lib/apt/apt.systemd.daily 

why does apt-file search --regexp '/usr/lib/apache2/modules/httpd.exp|/usr/lib/apt/apt.systemd.daily' only return

apache2-bin: /usr/lib/apache2/modules/httpd.exp 

The solution is intended to be used for an optimization of the GNOME build tool jhbuild. It should work an a large set of Ubuntu versions.

## What is the following regex trying to protect against?

I am looking at a Java web application that compares all incoming request params and cookies against the following regex. If it matches, it is considered “an attack” and refuses the request. I’m guessing it’s trying to prevent SQL injection / class loading or something, but I’m not sure. Can anyone help?

(.*\.|^|.*|\[('|"))(c|C)lass(\.|('|")]|\[).* 

## How to show ^ (to the power) in regex in PFLAP

How to show ^ (to the power) in regex in PFLAP

I am trying to convert this regex to NFA (3^+)(3*+2*)(1^+)(2+1)3(2^+ )(3+1)*(3+1)2

but it says “Operators are poorly formatted!”

Where ^ means power

So, the question is: does the power symbol (^) works in PFLAP?

thanks

## How to understand set notation and turn it into regex?

{w | w ∈ {a,b,c}*}

What does the above notation mean and how to turn it into regex?

my understanding is that this set notation will produce {abc, aabbcc, cab, bba} basically any number of a’s b’s and c’s in no particular order so the regex would look something like (a|b|c)* is this correct?

{w | w ∈ {b}* U {c}} and something like this means I have a language that contains any number of b’s or just a c {b, bbb, bb, bbbb, c} in regex b* | c is this correct?

## RegEx para filtrar certas palavras

Olá, estou tentando criar um RegEx que filtra por certas palavras, para ser utilizado na validação do nome digitado pelo usuário em uma conversa com um chatbot. Como se trata de filtrar palavrões, troquei os mesmos por “palavraox”, para que esta pergunta não ficasse ofensiva.

O que consegui fazer até agora é:

/^((?!palavrao1|palavrao2|palavrao3|Palavrao1|Palavrao2|Palavrao3|PALAVRAO1|PALAVRAO2|PALAVRAO3).)*$/  O problema é, se uma pessoa tiver o nome que contém algum destes palavrões, ela será filtrada. No caso, o nome “Cuca” não seria válido pelo exato motivo. Então gostaria de saber como seria para procurar pelo palavrão literalmente, não apenas se o nome contém tais palavrões. Obs: Sei que é possível usar a tag /i para tonar o RegEx case-insensitive, mas o chatbot infelizmente não aceita estas tags. ## Replacing text in a string with recursion and regex I am using tags to replace text before displaying output in a browser, similar to WordPress’ short codes. Example string: Hi, this is a block of text {{block:welcome}} and this is a system variable {{variable:system_version}} I have functions to replace these blocks accordingly, and I realize a foreach or while function will be the best way to deal with it, but unfortunately, replacing one {{...}} may introduce another. Hence, I opted for recursion until no more are found. Typical recursion is only once, but I have had two in one scenario. Maybe calling the function 3 times will work, but it sounds “wrong”. Now that is where the problem occurs: I do NOT want to replace them when they appear in: 1) A page where the URL you are calling contains something 2) Any form element such as <input> or <textarea>.  I need help on how to exclude from #2 above by means of a regex. My regex currently look like this: ^\{\{((?!keep).)*$  (I realize it may still be wrong, or need modification – does not quite work yet).

If the item contains “keep”, e.g., {{block:welcome:keep}} it should not be replaced, but when doing so, the recursion never stops, as I keep finding items to replace, and thus run out of memory, or get maximum nested level errors.

The reason why I want to do this, is because I do not want the content replaced when on an ADMIN page, or when you are editing form content.

Someone willing to give it a crack? I am using PHP, if that matters.

Thanks!

## Formatação condicional de numero de telefone Regex

Contexto: tenho um input que a medida que eu vou digitando uma funcao é chamada para verificar se o numero de telefone está no formato correto. Essa funcao deve aceitar numeros nos formatos: (XX)XXXXX-XXXX e (XX)XXXX-XXXX, e já aceita ambos os formatos!

Qual é o problema entao?: A funcao ao dar match no formato de 8 digitos não continua a correção caso o usuario digite o 9º digito.

Resumindo: quero que o regex identifique tanto o formato de 8 e 9 digitos, mas se for entrado 9 digitos, este formato que deve ser usado.

import React, {useState} from 'react'  function App(){     const [telefone, setTelefone] = useState("")      function handleTelefone(event){         const regex = /^$$?([0-9]{2})$$?([0-9]{4,5})\-?([0-9]{4})$/mg; var str = event.target.value; const subst = ($  1)$2-$  3;          const result = str.replace(regex, subst);          setTelefone(result);     }     return(         <>             <form>                 <input type="text" value={telefone} onChange={handleTelefone.bind(this)}/>             </form>         </>     ) }  export default App

## Kleene Star regex question, sed behavior?

Kleene Star with ‘sed’ is behaving as expected for me, with exception of a case where the input pattern is “ab” and the regex is “b*”. Does anyone know why this regex is not being matched against the pattern space?

This is the failure case:

$printf "ab\n" | sed -En 's/b*// p' | od -t c 0000000 a b \n 0000003  This case, without Kleene Star, behaves as expected: $   printf "ab\n" | sed -En 's/b// p' | od -t c 0000000   a  \n 0000002 

I’m trying to match the ‘b’ and replace it with nothing.

The pattern space is ‘ab’, beginning of line is unspecified, so I’m confused why /b*/ would not match a pattern of zero or more ‘b’s, in this case ‘b’.

Oddly, this case works with the ‘.’ prepended to the ‘*’:

# fails to match $printf "abb\n" | sed -En 's/b*// p' | od -t c 0000000 a b b \n 0000004 # matches with .* !$   printf "abb\n" | sed -En 's/b.*// p' | od -t c 0000000   a  \n 0000002 

Kleene Star matches zero or more occurrences of the preceding alphabet (in this case a single character).

By definition:

$$V^0 = \{\epsilon\}$$

$$V^1 = V$$

$$\forall i ( (i \gt 0) \land (V^{i + 1} = \{ wv : w \in V^i \land v \in V )\}$$

Therefore $$V^0 = \{ \epsilon\}$$, $$V^1 = \{ \epsilon \cdot b\}$$, $$V^2 = \{ \epsilon \cdot b \cdot b\}$$.

$$V^* = \bigcup\limits_{i\ge0} V^i = V^0 \cup V^1 \cup …$$ which I have specified by /b*/.

The following cases agree with my understanding of sed and Kleene Star:

# * : matches 0 or more occurances # no match \$   printf "a\n" | sed -En 's/b*// p' | od -t c 0000000   a  \n 0000002  # match a printf "a\n" | sed -En 's/a*// p' | od -t c 0000000  \n 0000001  # match a printf "ab\n" | sed -En 's/a*// p' | od -t c 0000000   b  \n 0000002  # match aa printf "aab\n" | sed -En 's/a*// p' | od -t c 0000000   b  \n 0000002 

I tested using BSD and GNU sed, both have the same results.

Thanks!