Java Regex .split String of CFGs

Been having problems parsing a line String from a CFG file,

the input string is:

String str = "The <animal> loves to <activity>.";

I’ve tried to use split with regex to split by the Non-terminals (<*>), however it’s not producing the desired results:

What I’ve tried:

str.split("(?=<)");

Output:

"The ", "<animal> loves to", "<activity>."

Desired output:

"The ", "<animal>", " loves to ", "<activity>", "." 

google sheets – Using regex to select the text between two characters IF there is text

I have this text:

<a class="_f5rco33" href="http://webapps.stackexchange.com/account-settings"><div class="_ojs7nk">Account</div></a>

And I want to grab the word “Account”, but when I use this regex

">((^<)*)<"

It returns “” because “settings”><div” is the first valid instance.

My tags and text will change every time I run this, but I want to select what’s between > and <, IF it is text, and I can’t figure it out.

python – How to use regex in an API call for coinapi.io?

I would like to obtain the trading volume of bitcoin over all exchanges via coinapi.io. According to https://docs.coinapi.io/#security-list-request-x, it seems that I can obtain the trading between any asset with bitcoin with just two API call (since there is an API call limit of 100 per 24 hours).

This is from the website:

Exact match or regex for the symbol identifier filtering, eg. ^BITSTAMP_(.*)_USD$ or BITSTAMP_SPOT_BTC_USD, have in mind that regex is enabled only if value string starts with ^ or/and ends with $.

Therefore the 2 URL I thought would work is:

https://rest.coinapi.io/v1/ohlcv/^(.*)_(.*)_BTC$/history?period_id=1DAY&time_start=2017-01-01T00:00:00

https://rest.coinapi.io/v1/ohlcv/^(.*)_BTC_(.*)$/history?period_id=1DAY&time_start=2017-01-01T00:00:00

However, I only got this error for the first API call: “error”: “Requested symbol_id is invalid does not exists.”

I also tried with “^BITSTAMP_(.*)_USD$” from the documentation, same error.

Then I put the sign “$” at the end of the url instead of the original position: I got this error (it seems that “$” is considered as a part of the value for time):

  "error": "Wrong format of time_start parameter"

So does anyone know how to use regex in API-call of coinapi.io?

I am using python for the API call.

javascript – Jquery regex patterns not validating

I’m working on a web page using Java servlets and JSPs. I’m currently having trouble with my login page using HTML forms and using Jquery for some quick client-side validation using regex patterns. I’m running and compiling on the latest version of Intellij ultimate.

When writing the validation using regex patterns and testing it the first time it worked perfectly fine and displayed the message only when it broke the regex pattern. Now, however, after starting my laptop back up it’s saying my pattern is being broken even when I’m giving a valid input. I’ve tested my regex online and all my patterns are doing what I want them to.

For some reason it allows me to enter one character into the input field and it accepted it but any more than one character and it displays my message saying the pattern has been broken.

Is this a problem with the way I’m writing it or is it a bug with Jquery?

I have my javascript written in a different file and have linked as so in the head along with the links to use Jquery:

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/jquery.validate.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery-validate/1.19.1/additional-methods.min.js"></script>
<script src="form_validation.js"></script>

My form:

<form action="CreateAccount" method="post" name = "CreateAccountForm" id = "CreateAccountForm">
    <label for="firstname">First name:</label><br>
    <input type="text" id="firstname" name="firstname"><br>

    <label for="lastname">Last name:</label><br>
    <input type="text" id="lastname" name="lastname"><br>

    <label for="username">Username:</label><br>
    <input type="text" id="username" name="username"><br>

    <label for="password">Password</label><br>
    <input type="password" id="password" name="password"><br>

    <label for="phone">Phone Number</label><br>
    <input type="text" id="phone" name="phone"><br>

    <label for="email">Email</label><br>
    <input type="email" id="email" name="email"><br><br>

    <input type="submit" value="Submit">

</form>

My Jquery:

$(function () {
    $('CreateAccountForm').validate({
        rules: {
            firstname:{
                required:true,
                pattern: /^(a-zA-Z)+$/,
                max_length: 50

            },
            lastname:{
                required:true,
                pattern: /^(a-zA-Z)+$/,
                max_length: 50
            },
            username:{
                required:true,
                pattern: /^(^ )+$/,
                max_length: 50
            },
            password:{
                required:true,
                pattern: /^(?=.*(a-z))(?=.*(A-Z))(?=.*d)(a-zA-Zd){8,15}$/
            },
            phone:{
                required:true,
                pattern: /^d{2}-d{4}-d{7}$/
            },
            email:{
                required:true,
                email:true,
                max_length: 50
            }

        },
        messages:{
            firstname:{
                required: " A first name is required",
                pattern: " First name must only contain characters a-z",
                max_length: "Must be less than 50 characters"


            },
            lastname:{
                required: " A last name is required",
                pattern: " Last name must only contain characters a-z",
                max_length: "Must be less than 50 characters"
            },
            username:{
                required: " A user name is required",
                pattern: " User name cannot have spaces",
                max_length: "Must be less than 50 characters"
            },
            password:{
                required: " A password is required",
                pattern: " Password must contain: " +
                    "At least one upper case letter, " +
                    "At least one lower case letter, " +
                    "At least one number " +
                    "and be between 8-15 characters."
            },
            phone:{
                required: " A phone number is required",
                pattern: " Phone number must be in the format **-****-*******"
            },
            email:{

                required: " An email is required",
                email: " Not a valid email address format",
                max_length: "Must be less than 50 characters"
            }

        }

    })

})

Alterar parte de pattern ou regex javascript dinamicamente

Estou fazendo uma requisição ajax que vai me devolver uma página “X”. Meu objetivo é cortar a página e manipular o outerHTML para retornar apenas as que correspondem a um pattern/regex específico.

var xmlhttp = new XMLHttpRequest();
      xmlhttp.onreadystatechange = function() {
        if (this.readyState == 4 && this.status == 200) {
          var body = this.responseXML.body.outerHTML;
          var main = body.slice(body.indexOf("<main"), body.indexOf("</main>"));
          var regex = /<tr(^>)*>(?:(?!<|AQUI)(sS))*(?:<(?!/?tr)(^>)*>(?:(?!<|AQUI)(sS))*)*AQUI(sS)*?</tr>/gi;

          if(regex.test(main)) {
            var matches = main.match(regex);
            $('#resposta').html('<p class="result">Os ramais relacionados à <strong>' + setor + '</strong> são:');
            for(i = 0; i < matches.length; i++){
              $('#resposta').append(matches(i));
              $('#resposta').append('<p class="more"><a href="intranet/ramais">Para mais detalhes acesse os Ramais do TJPB</a></p>');
            }
          } else {
            $('#resposta').html('Nenhuma combinação encontrada');
          }
        }
      };
      xmlhttp.open("GET",url, true);
      xmlhttp.responseType = "document";
      xmlhttp.send();

O Pattern está funcionando perfeitamente, só que está estático. A questão é que não estou conseguindo manipular ele, alterá-lo:

/<tr(^>)>(?:(?!<|AQUI)(sS))(?:<(?!/?tr)(^>)>(?:(?!<|AQUI)(sS)))AQUI(sS)?</tr>/gi

Onde tem “AQUI” gostaria de mudar o valor dinamicamente de acordo com um parâmetro. Vamos supor que eu precise mudar para “abcd” ou “efgh”, por exemplo.

ps. a variável url é populada anteriormente e retorna a url da página

Email (Regex PHP) – Stack Overflow em Português

Estou tentando substituir letras por asteríscos de um email usando o preg_replace() do php, mas o php pega todas as letras do email, porém eu só quero colocar os asteríscos nas primeiras letras.
exemplo:
entrada: emailteste2020@gmail.com
saida: *********2020@gmail.com

mas meu código está pegando todas as letras e substituindo por asteríscos
exemplo:
entrada: emailteste2020@gmail.com
coloquei os hífens no lugar dos asterícos para não ficar em negrito
saida: *********2020@—-.—

meu código:

    $email="emailteste16@gmail.com";

    $emailRegex=preg_replace('/((a-z))/','*', $email);
    
    echo $email;
    echo "<br>";
    echo $emailRegex;```

regex – Como funciona expressão regular com duplo range?

Eu estou estudando regex e tive uma dúvida ao lidar com o operador range (-).

Eu entendo que um range como (a-z) significa “todo o alfabeto em letras minúsculas” e que um range como (^A-R)seria algo como “todas as letras maiúsculas que não estejam entre A e R” (não estou muito seguro sobre esta interpretação).

Mas o que significa uma expressão com duplo range do tipo (^A-RU-Z)?

centos7 – block ips with csf using a custom regex from a custom log file

I have wordpress on two web server nodes behind a loadbalancer server (all of them have CSF). All of them are centos7 and also directadmin is installed (if relevant). and I log “failed login IPs” on web nodes in a file in order to use this custom regex on it:

if (($globlogs{CUSTOM1_LOG}{$lgfile}) and ($line =~ /^(d+.d+.d+.d+)/)) {
     return ("Failed WordPress login from",$1,"wordpresslogin","5","80,443","3600","0");
}

The regex is placed currectly in /etc/csf/regex.custom.pm
this works on both web servers. But I figured out this is not what I need to do, to block those IPs. I needed to log those IPs on the loadbalancer, so I wrote this script and add it to the cronjob to run every minute:

#!/bin/bash

WEB1_IP="X.X.X.X"
WEB2_IP="Y.Y.Y.Y"

LOG_URL="/login_logs.txt"
LOG_PATH="/home/login_logs.txt"

wget -q -O - "$WEB1_IP""$LOG_URL" | tail -n+2 > "$LOG_PATH"
wget -q -O - "$WEB2_IP""$LOG_URL" | tail -n+2 >> "$LOG_PATH"

Then I add the same regex to CSF on loadbalancer with the new log path.

But It’s not working. IPs get blocked on web nodes but won’t on the loadbalancer server. I don’t know how csf and lfd reads those logs but the only difference between web nodes and loadbalancer is that on web nodes, the log file is being written line by line. But on loadbalancer the log file is being written at once and gets replaced every minute. Can you help me?