java – regex always answers immediately with find ()

Hello, I'm making a code that receives HTML and returns whether it contains one of three possible words as shown in the code below. However, the final always returns true, regardless of which matcher I use. Would anyone know what to say?

public class RegexTests {
public static boolean RegexCases(StringBuilder HTMLresult){
    String BF = "black friday";
    String Promo = "promoção";
    String Password = "senha";

    Pattern patternPassword = Pattern.compile(Password);
    Pattern patternPromo = Pattern.compile(Promo);
    Pattern patternBF = Pattern.compile(BF);

    Matcher matcherPassword = patternPassword.matcher(HTMLresult);
    Matcher matcherPromo = patternPromo.matcher(HTMLresult);
    Matcher matcherBF = patternBF.matcher(HTMLresult);

    if(matcherBF.find()){
        return true;
    }
    else return false;
}}

Javascript – Prettier Pug Plugin – performance, documentation, division, regex improvements

import { Doc, FastPath, format, Options, Parser, ParserOptions, Plugin, util } from 'prettier';
import * as lex from 'pug-lexer';
import { AttributeToken, EndAttributesToken, Token } from 'pug-lexer';
import { DOCTYPE_SHORTCUT_REGISTRY } from './doctype-shortcut-registry';
import { createLogger, Logger, LogLevel } from './logger';
import {
  formatCommentPreserveSpaces,
  options as pugOptions,
  PugParserOptions,
  resolveAttributeSeparatorOption
} from './options';

const { makeString } = util;

const logger: Logger = createLogger(console);
if (process.env.NODE_ENV === 'test') {
  logger.setLogLevel(LogLevel.DEBUG);
}

function previousNormalAttributeToken(tokens: Token(), index: number): AttributeToken | undefined {
  for (let i: number = index - 1; i > 0; i--) {
    const token: Token = tokens(i);
    if (token.type === 'start-attributes') {
      return;
    }
    if (token.type === 'attribute') {
      if (token.name !== 'class' && token.name !== 'id') {
        return token;
      }
    }
  }
  return;
}

function printIndent(previousToken: Token, indent: string, indentLevel: number): string {
  switch (previousToken?.type) {
    case 'newline':
    case 'outdent':
      return indent.repeat(indentLevel);
    case 'indent':
      return indent;
  }
  return '';
}

function formatText(text: string, singleQuote: boolean): string {
  let result: string = '';
  while (text) {
    const start = text.indexOf('{{');
    if (start !== -1) {
      result += text.slice(0, start);
      text = text.substring(start + 2);
      const end = text.indexOf('}}');
      if (end !== -1) {
        let code = text.slice(0, end);
        code = code.trim();
        code = format(code, { parser: 'babel', singleQuote: !singleQuote, printWidth: 9000 });
        if (code.endsWith(';n')) {
          code = code.slice(0, -2);
        }
        result += `{{ ${code} }}`;
        text = text.slice(end + 2);
      } else {
        result += '{{';
        result += text;
        text = '';
      }
    } else {
      result += text;
      text = '';
    }
  }
  return result;
}

function unwrapLineFeeds(value: string): string {
  return value.includes('n')
    ? value
        .split('n')
        .map((part) => part.trim())
        .join('')
    : value;
}

export const plugin: Plugin = {
  languages: (
    {
      name: 'Pug',
      parsers: ('pug'),
      tmScope: 'text.jade',
      aceMode: 'jade',
      codemirrorMode: 'pug',
      codemirrorMimeType: 'text/x-pug',
      extensions: ('.jade', '.pug'),
      linguistLanguageId: 179,
      vscodeLanguageIds: ('jade')
    }
  ),
  parsers: {
    pug: {
      parse(text: string, parsers: { (parserName: string): Parser }, options: ParserOptions): Token() {
        logger.debug('(parsers:pug:parse):', { text });
        const tokens = lex(text);
        // logger.debug('(parsers:pug:parse): tokens', JSON.stringify(tokens, undefined, 2));
        // const ast: AST = parse(tokens, {});
        // logger.debug('(parsers:pug:parse): ast', JSON.stringify(ast, undefined, 2));
        return tokens;
      },
      astFormat: 'pug-ast',
      hasPragma(text: string): boolean {
        return text.startsWith('//- @prettiern') || text.startsWith('//- @formatn');
      },
      locStart(node: any): number {
        logger.debug('(parsers:pug:locStart):', { node });
        return 0;
      },
      locEnd(node: any): number {
        logger.debug('(parsers:pug:locEnd):', { node });
        return 0;
      },
      preprocess(text: string, options: ParserOptions): string {
        logger.debug('(parsers:pug:preprocess):', { text });
        return text;
      }
    }
  },
  printers: {
    'pug-ast': {
      print(
        path: FastPath,
        {
          printWidth,
          singleQuote,
          tabWidth,
          useTabs,
          attributeSeparator,
          commentPreserveSpaces,
          semi
        }: ParserOptions & PugParserOptions,
        print: (path: FastPath) => Doc
      ): Doc {
        const tokens: Token() = path.stack(0);

        let result: string = '';
        let indentLevel: number = 0;
        let indent: string = ' '.repeat(tabWidth);
        if (useTabs) {
          indent = 't';
        }
        let pipelessText: boolean = false;
        let pipelessComment: boolean = false;

        const alwaysUseAttributeSeparator: boolean = resolveAttributeSeparatorOption(attributeSeparator);

        let startTagPosition: number = 0;
        let startAttributePosition: number = 0;
        let previousAttributeRemapped: boolean = false;
        let wrapAttributes: boolean = false;

        const codeInterpolationOptions: Options = {
          singleQuote: !singleQuote,
          printWidth: 9000,
          endOfLine: 'lf'
        };

        if (tokens(0)?.type === 'text') {
          result += '| ';
        }

        for (let index: number = 0; index < tokens.length; index++) {
          const token: Token = tokens(index);
          const previousToken: Token | undefined = tokens(index - 1);
          const nextToken: Token | undefined = tokens(index + 1);
          logger.debug('(printers:pug-ast:print):', JSON.stringify(token));
          switch (token.type) {
            case 'tag':
              result += printIndent(previousToken, indent, indentLevel);
              if (!(token.val === 'div' && (nextToken.type === 'class' || nextToken.type === 'id'))) {
                result += token.val;
              }
              startTagPosition = result.length;
              break;
            case 'start-attributes':
              if (nextToken?.type === 'attribute') {
                previousAttributeRemapped = false;
                startAttributePosition = result.length;
                result += '(';
                const start: number = result.lastIndexOf('n') + 1;
                let lineLength: number = result.substring(start).length;
                logger.debug(lineLength, printWidth);
                let tempToken: AttributeToken | EndAttributesToken = nextToken;
                let tempIndex: number = index + 1;
                while (tempToken.type === 'attribute') {
                  lineLength += tempToken.name.length + 1 + tempToken.val.toString().length;
                  logger.debug(lineLength, printWidth);
                  tempToken = tokens(++tempIndex) as AttributeToken | EndAttributesToken;
                }
                if (lineLength > printWidth) {
                  wrapAttributes = true;
                }
              }
              break;
            case 'attribute': {
              if (typeof token.val === 'string') {
                const surroundedByQuotes: boolean =
                  (token.val.startsWith('"') && token.val.endsWith('"')) ||
                  (token.val.startsWith("'") && token.val.endsWith("'"));
                if (surroundedByQuotes) {
                  if (token.name === 'class') {
                    // Handle class attribute
                    let val = token.val;
                    val = val.substring(1, val.length - 1);
                    val = val.trim();
                    val = val.replace(/ss+/g, ' ');
                    const classes: string() = val.split(' ');
                    const specialClasses: string() = ();
                    const validClassNameRegex: RegExp = /^-?(_a-zA-Z)+(_a-zA-Z0-9-)*$/;
                    for (const className of classes) {
                      if (!validClassNameRegex.test(className)) {
                        specialClasses.push(className);
                        continue;
                      }
                      // Write css-class in front of attributes
                      const position: number = startAttributePosition;
                      result = (
                        result.slice(0, position),
                        `.${className}`,
                        result.slice(position)
                      ).join('');
                      startAttributePosition += 1 + className.length;
                      result = result.replace(/div./, '.');
                    }
                    if (specialClasses.length > 0) {
                      token.val = makeString(
                        specialClasses.join(' '),
                        singleQuote ? "'" : '"',
                        false
                      );
                      previousAttributeRemapped = false;
                    } else {
                      previousAttributeRemapped = true;
                      break;
                    }
                  } else if (token.name === 'id') {
                    // Handle id attribute
                    let val = token.val;
                    val = val.substring(1, val.length - 1);
                    val = val.trim();
                    const validIdNameRegex: RegExp = /^-?(_a-zA-Z)+(_a-zA-Z0-9-)*$/;
                    if (!validIdNameRegex.test(val)) {
                      val = makeString(val, singleQuote ? "'" : '"', false);
                      result += `id=${val}`;
                      break;
                    }
                    // Write css-id in front of css-classes
                    const position: number = startTagPosition;
                    result = (result.slice(0, position), `#${val}`, result.slice(position)).join(
                      ''
                    );
                    startAttributePosition += 1 + val.length;
                    result = result.replace(/div#/, '#');
                    if (previousToken.type === 'attribute' && previousToken.name !== 'class') {
                      previousAttributeRemapped = true;
                    }
                    break;
                  }
                }
              }

              const hasNormalPreviousToken: AttributeToken | undefined = previousNormalAttributeToken(
                tokens,
                index
              );
              if (
                previousToken?.type === 'attribute' &&
                (!previousAttributeRemapped || hasNormalPreviousToken)
              ) {
                if (alwaysUseAttributeSeparator || /^((|(|:).*/.test(token.name)) {
                  result += ',';
                }
                if (!wrapAttributes) {
                  result += ' ';
                }
              }
              previousAttributeRemapped = false;

              if (wrapAttributes) {
                result += 'n';
                result += indent.repeat(indentLevel + 1);
              }

              result += `${token.name}`;
              if (typeof token.val === 'boolean') {
                if (token.val !== true) {
                  result += `=${token.val}`;
                }
              } else {
                let val = token.val;
                if (/^((v-bind|v-on|v-slot)?:|v-model|v-on|@).*/.test(token.name)) {
                  // Format Vue expression
                  val = val.trim();
                  val = val.slice(1, -1);
                  val = format(val, {
                    parser: '__vue_expression' as any,
                    ...codeInterpolationOptions
                  });
                  val = unwrapLineFeeds(val);
                  const quotes: "'" | '"' = singleQuote ? "'" : '"';
                  val = `${quotes}${val}${quotes}`;
                } else if (/^((.*)|(.*))$/.test(token.name)) {
                  // Format Angular action or binding
                  val = val.trim();
                  val = val.slice(1, -1);
                  val = format(val, {
                    parser: '__ng_interpolation' as any,
                    ...codeInterpolationOptions
                  });
                  val = unwrapLineFeeds(val);
                  const quotes: "'" | '"' = singleQuote ? "'" : '"';
                  val = `${quotes}${val}${quotes}`;
                } else if (/^*.*$/.test(token.name)) {
                  // Format Angular directive
                  val = val.trim();
                  val = val.slice(1, -1);
                  val = format(val, { parser: '__ng_directive' as any, ...codeInterpolationOptions });
                  const quotes: "'" | '"' = singleQuote ? "'" : '"';
                  val = `${quotes}${val}${quotes}`;
                } else if (/^(("'){{)(.*)(}}("'))$/.test(val)) {
                  // Format Angular interpolation
                  val = val.slice(3, -3);
                  val = val.trim();
                  val = val.replace(/ss+/g, ' ');
                  // val = format(val, {
                  //   parser: '__ng_interpolation' as any,
                  //   ...codeInterpolationOptions
                  // });
                  const quotes: "'" | '"' = singleQuote ? "'" : '"';
                  val = `${quotes}{{ ${val} }}${quotes}`;
                } else if (/^("')(.*)("')$/.test(val)) {
                  val = makeString(val.slice(1, -1), singleQuote ? "'" : '"', false);
                } else if (val === 'true') {
                  // The value is exactly true and is not quoted
                  break;
                } else if (token.mustEscape) {
                  val = format(val, {
                    parser: '__js_expression' as any,
                    ...codeInterpolationOptions
                  });
                } else {
                  // The value is not quoted and may be js-code
                  val = val.trim();
                  val = val.replace(/ss+/g, ' ');
                  if (val.startsWith('{ ')) {
                    val = `{${val.substring(2, val.length)}`;
                  }
                }

                if (token.mustEscape === false) {
                  result += '!';
                }

                result += `=${val}`;
              }
              break;
            }
            case 'end-attributes':
              if (wrapAttributes) {
                result += 'n';
                result += indent.repeat(indentLevel);
              }
              wrapAttributes = false;
              if (result.endsWith('(')) {
                // There were no attributes
                result = result.substring(0, result.length - 1);
              } else if (previousToken?.type === 'attribute') {
                result += ')';
              }
              if (nextToken?.type === 'text' || nextToken?.type === 'path') {
                result += ' ';
              }
              break;
            case 'indent':
              result += 'n';
              result += indent.repeat(indentLevel);
              indentLevel++;
              break;
            case 'outdent':
              if (previousToken?.type !== 'outdent') {
                if (token.loc.start.line - previousToken.loc.end.line > 1) {
                  // Insert one extra blank line
                  result += 'n';
                }
                result += 'n';
              }
              indentLevel--;
              break;
            case 'class':
              result += printIndent(previousToken, indent, indentLevel);
              result += `.${token.val}`;
              if (nextToken?.type === 'text') {
                result += ' ';
              }
              break;
            case 'eos':
              // Remove all newlines at the end
              while (result.endsWith('n')) {
                result = result.substring(0, result.length - 1);
              }
              // Insert one newline
              result += 'n';
              break;
            case 'comment': {
              result += printIndent(previousToken, indent, indentLevel);
              if (previousToken && !('newline', 'indent', 'outdent').includes(previousToken.type)) {
                result += ' ';
              }
              result += '//';
              if (!token.buffer) {
                result += '-';
              }
              result += formatCommentPreserveSpaces(token.val, commentPreserveSpaces);
              if (nextToken.type === 'start-pipeless-text') {
                pipelessComment = true;
              }
              break;
            }
            case 'newline':
              if (previousToken && token.loc.start.line - previousToken.loc.end.line > 1) {
                // Insert one extra blank line
                result += 'n';
              }
              result += 'n';
              break;
            case 'text': {
              let val = token.val;
              let needsTrailingWhitespace: boolean = false;

              if (pipelessText) {
                switch (previousToken?.type) {
                  case 'newline':
                    result += indent.repeat(indentLevel);
                    result += indent;
                    break;
                  case 'start-pipeless-text':
                    result += indent;
                    break;
                }

                if (pipelessComment) {
                  val = formatCommentPreserveSpaces(val, commentPreserveSpaces, true);
                }
              } else {
                if (nextToken && val.endsWith(' ')) {
                  switch (nextToken.type) {
                    case 'interpolated-code':
                    case 'start-pug-interpolation':
                      needsTrailingWhitespace = true;
                      break;
                  }
                }

                val = val.replace(/ss+/g, ' ');

                switch (previousToken?.type) {
                  case 'newline':
                    result += indent.repeat(indentLevel);
                    if (/^ .+$/.test(val)) {
                      result += '|n';
                      result += indent.repeat(indentLevel);
                    }
                    result += '|';
                    if (/.*S.*/.test(token.val) || nextToken?.type === 'start-pug-interpolation') {
                      result += ' ';
                    }
                    break;
                  case 'indent':
                    result += indent;
                    result += '|';
                    if (/.*S.*/.test(token.val)) {
                      result += ' ';
                    }
                    break;
                  case 'interpolated-code':
                  case 'end-pug-interpolation':
                    if (/^ .+$/.test(val)) {
                      result += ' ';
                    }
                    break;
                }

                val = val.trim();
                val = formatText(val, singleQuote);

                val = val.replace(/#({|()/g, '\#$1');
              }

              if (
                ('tag', 'id', 'interpolation', 'call', '&attributes', 'filter').includes(
                  previousToken?.type
                )
              ) {
                val = ` ${val}`;
              }

              result += val;
              if (needsTrailingWhitespace) {
                result += ' ';
              }
              break;
            }
            case 'interpolated-code':
              switch (previousToken?.type) {
                case 'tag':
                case 'class':
                case 'id':
                case 'end-attributes':
                  result += ' ';
                  break;
                case 'start-pug-interpolation':
                  result += '| ';
                  break;
                case 'indent':
                case 'newline':
                case 'outdent':
                  result += printIndent(previousToken, indent, indentLevel);
                  result += '| ';
                  break;
              }
              result += token.mustEscape ? '#' : '!';
              result += `{${token.val}}`;
              break;
            case 'code': {
              result += printIndent(previousToken, indent, indentLevel);
              if (!token.mustEscape && token.buffer) {
                result += '!';
              }
              result += token.buffer ? '=' : '-';
              let useSemi = semi;
              if (useSemi && (token.mustEscape || token.buffer)) {
                useSemi = false;
              }
              let val = token.val;
              try {
                const valBackup = val;
                val = format(val, {
                  parser: 'babel',
                  ...codeInterpolationOptions,
                  semi: useSemi,
                  endOfLine: 'lf'
                });
                val = val.slice(0, -1);
                if (val.includes('n')) {
                  val = valBackup;
                }
              } catch (error) {
                logger.warn(error);
              }
              result += ` ${val}`;
              break;
            }
            case 'id': {
              // Handle id attribute
              // Write css-id in front of css-classes
              let lastPositionOfNewline = result.lastIndexOf('n');
              if (lastPositionOfNewline === -1) {
                // If no newline was found, set position to zero
                lastPositionOfNewline = 0;
              }
              let position: number = result.indexOf('.', lastPositionOfNewline);
              if (position === -1) {
                position = result.length;
              }
              let _indent = '';
              switch (previousToken?.type) {
                case 'newline':
                case 'outdent':
                  _indent = indent.repeat(indentLevel);
                  break;
                case 'indent':
                  _indent = indent;
                  break;
              }
              result = (result.slice(0, position), _indent, `#${token.val}`, result.slice(position)).join(
                ''
              );
              break;
            }
            case 'start-pipeless-text':
              pipelessText = true;
              result += 'n';
              result += indent.repeat(indentLevel);
              break;
            case 'end-pipeless-text':
              pipelessText = false;
              pipelessComment = false;
              break;
            case 'doctype':
              result += 'doctype';
              if (token.val) {
                result += ` ${token.val}`;
              }
              break;
            case 'dot':
              result += '.';
              break;
            case 'block':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'block ';
              if (token.mode !== 'replace') {
                result += token.mode;
                result += ' ';
              }
              result += token.val;
              break;
            case 'extends':
              result += 'extends ';
              break;
            case 'path':
              if (('include', 'filter').includes(previousToken?.type)) {
                result += ' ';
              }
              result += token.val;
              break;
            case 'start-pug-interpolation':
              result += '#(';
              break;
            case 'end-pug-interpolation':
              result += ')';
              break;
            case 'interpolation':
              result += printIndent(previousToken, indent, indentLevel);
              result += `#{${token.val}}`;
              break;
            case 'include':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'include';
              break;
            case 'filter':
              result += printIndent(previousToken, indent, indentLevel);
              result += `:${token.val}`;
              break;
            case 'call': {
              result += printIndent(previousToken, indent, indentLevel);
              result += `+${token.val}`;
              let args: string | null = token.args;
              if (args) {
                args = args.trim();
                args = args.replace(/ss+/g, ' ');
                result += `(${args})`;
              }
              break;
            }
            case 'mixin': {
              result += printIndent(previousToken, indent, indentLevel);
              result += `mixin ${token.val}`;
              let args: string | null = token.args;
              if (args) {
                args = args.trim();
                args = args.replace(/ss+/g, ' ');
                result += `(${args})`;
              }
              break;
            }
            case 'if': {
              result += printIndent(previousToken, indent, indentLevel);
              const match = /^!((.*))$/.exec(token.val);
              logger.debug(match);
              result += !match ? `if ${token.val}` : `unless ${match(1)}`;
              break;
            }
            case 'mixin-block':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'block';
              break;
            case 'else':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'else';
              break;
            case '&attributes':
              result += `&attributes(${token.val})`;
              break;
            case 'text-html': {
              result += printIndent(previousToken, indent, indentLevel);
              const match: RegExpExecArray | null = /^<(.*?)>(.*)$/.exec(token.val);
              logger.debug(match);
              if (match) {
                result += `${match(1)} ${match(2)}`;
                break;
              }
              const entry = Object.entries(DOCTYPE_SHORTCUT_REGISTRY).find(
                ((key)) => key === token.val.toLowerCase()
              );
              if (entry) {
                result += entry(1);
                break;
              }
              result += token.val;
              break;
            }
            case 'each':
              result += printIndent(previousToken, indent, indentLevel);
              result += `each ${token.val}`;
              if (token.key !== null) {
                result += `, ${token.key}`;
              }
              result += ` in ${token.code}`;
              break;
            case 'while':
              result += printIndent(previousToken, indent, indentLevel);
              result += `while ${token.val}`;
              break;
            case 'case':
              result += printIndent(previousToken, indent, indentLevel);
              result += `case ${token.val}`;
              break;
            case 'when':
              result += printIndent(previousToken, indent, indentLevel);
              result += `when ${token.val}`;
              break;
            case ':':
              result += ': ';
              break;
            case 'default':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'default';
              break;
            case 'else-if':
              result += printIndent(previousToken, indent, indentLevel);
              result += `else if ${token.val}`;
              break;
            case 'blockcode':
              result += printIndent(previousToken, indent, indentLevel);
              result += '-';
              break;
            case 'yield':
              result += printIndent(previousToken, indent, indentLevel);
              result += 'yield';
              break;
            case 'slash':
              result += '/';
              break;
            default:
              throw new Error('Unhandled token: ' + JSON.stringify(token));
          }
        }

        logger.debug(result);
        return result;
      },
      embed(
        path: FastPath,
        print: (path: FastPath) => Doc,
        textToDoc: (text: string, options: Options) => Doc,
        options: ParserOptions
      ): Doc | null {
        // logger.debug('(printers:pug-ast:embed):', JSON.stringify(path, undefined, 2));
        return null;
      },
      insertPragma(text: string): string {
        return `//- @prettiern${text}`;
      }
    }
  },
  options: pugOptions as any,
  defaultOptions: {}
};

export const languages = plugin.languages;
export const parsers = plugin.parsers;
export const printers = plugin.printers;
export const options = plugin.options;
export const defaultOptions = plugin.defaultOptions;

Regex – Why do results vary depending on how the regular expression is executed in JavaScript?

What is the reason for the result mismatch that occurs when executing the same regular expression differently in JavaScript?

Regular expression:

^((a-z)(a-z0-9){0,30}.)?((?!d+.)(a-z0-9)(?:(a-z0-9-){0,24}(a-z0-9))?)(.(a-z){2,4}(?:.(a-z){2})?)$

Method 1 (works properly):

function valida_dominio(value){
    return /^((a-z)(a-z0-9){0,30}.)?((?!d+.)(a-z0-9)(?:(a-z0-9-){0,24}(a-z0-9))?)(.(a-z){2,4}(?:.(a-z){2})?)$/.test(value);
}

Method 2 (does not work properly):

function valida_dominio(value){
      let str_pattern = '^((a-z)(a-z0-9){0,30}.)?((?!d+.)(a-z0-9)(?:(a-z0-9-){0,24}(a-z0-9))?)(.(a-z){2,4}(?:.(a-z){2})?)$';
      let pattern = new RegExp(str_pattern, "i");
      return pattern.test(value);
}

The purpose of Method 2 is to be able to pass regular expressions as a string. But it doesn't work properly. For example:

  • approve the domain "cëa.br", which is invalid;
  • approves the domain "26character-asdfasdfasdfa.com.br" which is valid.

How does method 2 work properly? That is, how can you pass the regular expression via a string without the result deviating?

NOTE: In RegExp and Method 1, the regular expression works correctly.

regex – omit table name and period in SELECT query

If I do this query:

SELECT `tablename`.* FROM `something`.`tablename`

I get a table with column names that contain periods:

tablename.c1 | tablename.c2 | tablename.c3
------------------------------------------
     a       |       1      |     2
     b       |       1      |     3

I don't want that, I just want the column names c1. c2 and c3I can solve this by writing the following request:

SELECT `tablename`.`c1` as `c1`,
       `tablename`.`c2` as `c2`,
       `tablename`.`c3` as `c3` FROM `something`.`tablename`

However, I have a lot of columns, which makes it a very long query. How can I rename the columns from the first query or how can I do this right from the start?

(P. The query I am using contains multiple table references, so I will give the table name tablename.*)

Custom data grabber with regex problem

Hi there,

I want to use Scrapebox to remove all domain name mentions from a list that contains barely 4,000 website URLs.

The domain names are formatted on the pages as follows:

Scrapeboxforum.com
Scrapeboxinfo.net
Scrapeboxhub.org

The domain names are plain text. They are not hyperlinks.

If it helps, they are always in between

and

Elements.

I already have my list of almost 4000 URLs I want to scan.

I use 5 private proxies that have been tested and saved.
I think they are used when I use the Custom Data Grabber, but frankly I have problems with Scrapebox.

I created rules for incoming and outgoing messages for Scrapebox in the Windows firewall.
I can do other things that work with Scrapebox. For example internal links on the domain from which I get the URLs.

I created a custom data grabber module and a module mask underneath:

View post on imgur.com

I tried several regex examples and found the following:

Code:

^(?=.{1,253}.?$)(?:(?!-|(^.)+_)(A-Za-z0-9-_){1,63}(?

Source: https://stackoverflow.com/a/41193739/5048548

I tested it with the tool at https://regex101.com/ and 3 sample URLs are shown as matches (as far as I can tell?):

View post on imgur.com

However, when I start my module, I only get the following:

View post on imgur.com

The module data folder contains a CSV file with two odd characters in the first cell each time the module is executed:

View post on imgur.com

I have accessed several of the URLs via browseo.net and the domain names on these URLs are readable according to this tool.

Does anyone know where I'm wrong here?
Or is there a better way to remove MENTIONS domain names from a list of URLs?

Thank you in advance!

Regex – How are the values ​​of one array passed from bottom to top to another?

I know this is very simple and easy, but I am new to WordPress, PHP and JS.

$ classes = array ();
array_push ($ classes, $ match);
foreach ($ classes as $ names => $ text) {

preg_match (& # 39; / (.?)/ s & # 39 ;, $ sample, $ match);
preg_match (& # 39; / (.
?)

/ s & # 39 ;, $ sample, $ match);

echo $ match (1);

I want to get the values ​​of $ match declared below and use them as the values ​​of $ classes declared above. Because I want the $ text variable below to work. I hope I'm clear enough.

  • In other words, I want to find the number of echoes from $ match (1) and use it as the length of $ classes.

java – replace negative lookbehind regex

This method should return all occurrences of quoted strings. However, a single quote ( ’) should be treated like a normal single quote (just like a double quote in Java). Example: "This is not easy" The method should return the single string "isn't".
My code:

public static List findSingleQuotedTextWithEscapes(String input) {
        Pattern pattern = Pattern.compile ("(?

How would I replace the negative view behind it?

Custom post types – regex with a possible hyphen

I am working on a construction site for cars.
I wrote a regular expression that works until marks are separated by a hyphen.

These are two examples I want to match:

  • class-s / ford-shelby-gt350r
  • Class-s / exotic-rides-w70

The regex that I used for this is

((a-z-)+)/((a-z)+(-)*(a-z)+)-((a-zA-Z0-9)+(-)*(a-z0-9)+)/?$

But that fits Shelby as a brand, not a type.

That's how I use it in WordPress

$wp_rewrite->add_permastruct( 'cars', 'cars/%class%/%brand%-%postname%/', false );
add_rewrite_rule( 'cars/((a-zA-Z-)+)/((a-zA-Z)+)-((a-zA-Z0-9-)+)/?$', 'index.php?post_type=as_car&name=$matches(3)', 'top' );

I think I have to check (with a lookup) to see if there is a hyphen in the mark, but I don't know how to do it.

Can somebody help me with it?

This is a link to my regex editor: https://regex101.com/r/sI7bW4/138

Java – Simplification of regex expression: calendar

I want to parse a date string using the following general format: day of the week, dd-mo-yyyy hh: mm: ss. The calendar should also accept the following:

  1. a date without a weekday
  2. Spaces instead of hyphens
  3. Allow month not case sensitive (e.g. allow "Jan", "JAN" and "jAn")
  4. two-digit year
  5. a missing time zone
  6. Allow multiple spaces, wherever a single space is allowed.

My code:

public static Calendar parseDate(String input) {
    List months = Arrays.asList("jan", "feb", "mar", "apr", "may", "jun", "jul", "aug", "sep", "oct", "nov", "dec");
    Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
    Pattern pattern = Pattern.compile ("(?:(A-Z)(a-z)(a-z),\s+)?((0-2)(0-9)|(3)(0-1))(?:\s+|-)((a-zA-z){3})(?:\s+|-)((0-9){2,4})(?:\s+)((0-1)(0-9)|(2)(0-3)):((0-5)(0-9)):((0-9){2})(?:\s+GMT|$)");
    Matcher matcher = pattern.matcher (input);
    Calendar calendar = Calendar.getInstance (TimeZone.getTimeZone ("GTM"));
    if ( !matcher.find () ){
        return null;
    }
    int dayOfMonth = Integer.parseInt (matcher.group (1)); //since the first group is the time zone
    int month = months.indexOf (months.indexOf(matcher.group(2).toLowerCase()));
    int year = Integer.parseInt (matcher.group (3));
    if (year >= 0 && year <= 69){
        year += 2000;
    }
    if ( year >= 70 && year <= 99 ) {
        year += 1900;
    }
    int hours = Integer.parseInt(matcher.group(4));
    int minutes = Integer.parseInt(matcher.group(5));
    int seconds = Integer.parseInt(matcher.group(6));
    cal.set(year, month, dayOfMonth, hours, minutes, seconds);
    return calendar;
}

My question is how to improve "(?:(A-Z)(a-z)(a-z),\s+)?((0-2)(0-9)|(3)(0-1))(?:\s+|-)((a-zA-z){3})(?:\s+|-)((0-9){2,4})(?:\s+)((0-1)(0-9)|(2)(0-3)):((0-5)(0-9)):((0-9){2})(?:\s+GMT|$)"?
EDIT: I can only import regex matchers and patterns and ArrayList. The only additional methods are: months.indexOf, Calendar.set, Integer.parseInt
and String.toLowerCase

Fail2ban regex for special protocol format

I have a log file with lines that look like this:

2019-12-21 20:30:02 index [WARNING]: authenticate: failed login attempt {"action":"login","username":"tgbtgbtgbtgb","ip":"61.142.184.152"} - {"file":"Login.php","line":147, ...

I set up a filter in Fail2ban with the following regular expression:

"%Y-%m-%d %H:%M:%S" index [WARNING]: authenticate: failed login attempt {"action":"login","username":".*","ip":"".*

Unfortunately, Fail2ban cannot intercept the failed login attempts based on the regular expression above. What can be wrong

The configuration block in /etc/fail2ban/jail.local is:

[appname]
enabled  = true
filter   = appname
logpath  = /path/to/logfile.log
port     = 80,443
maxretry = 3
bantime = 259200

Fail2ban can also read the log file. Thank you for your help!