Regular Expression Example

  • Last update:December 19, 2024
  • Overview

    When processing data, regular expressions are often used to describe certain string-matching rules for text filtering.

    Expected Effect

    For example, you need to judge the URL text field. If all characters in a field are numbers, mark the field as Pure Number. Otherwise, mark the field as Others, as shown in the following figure.

    1.png

    Implementation Method

    You can use the REGEXP function to judge whether the characters in a field are pure numbers.

    Then you can use the IF function to make marks.

    Example

    Sample data: Scene Document.xlsx

    Upload the sample data to FineBI.

    2.png

    Method One

    Click Formula Column, enter Pure Numbers in Name of Added Formula Column, and enter IF(REGEXP(URL,"\\d*")=1,"Pure Number","Others"), as shown in the following figure.

    3.png

    The following table describes the formula.

    Formula
    Description

    REGEXP(URL,"\\d*")

    If all characters in a URL field are numbers, the function returns 1. Otherwise, the function returns 0.

    • \d represents matching numbers. To use the \ character, you need to add another backslash. For example, the formula REGEXP(String,"\d") is invalid and needs to be changed to REGEXP(String,"\\d"), as shown in the following figure.

    • * represents matching the preceding sub-expression for zero or more times.

    IF(REGEXP(URL,"\\d*")=1,"Pure   Number","Others")

    If the returned value is 1, the function outputs Pure Number. Otherwise, the function outputs Others.

    Method Two

    You can also use IF(REGEXP(URL,"^[0-9]*$")=1,"Pure Number","Others"), as shown in the following figure.

    4.png

    The following table describes the formula.

    Formula
    Description

    (REGEXP(URL,"^[0-9]*$")

    If all characters in a URL field are numbers, the function returns 1. Otherwise, the function returns 0.

    ^ represents the beginning of the input matched string.

    [0-9]* represents matching multiple numbers, and [0-9] represents matching a single number. * represents matching the preceding sub-expression for zero or more times.

    $ represents the end of the input matched string.

    IF(REGEXP(URL,"^[0-9]*$")=1,"Pure   Number","Others")

    If the returned value is 1, the function outputs Pure Number. Otherwise, the function outputs Others.

    The following figure explains the regular expression.

    5.png

    附件列表


    主题: System Management
    • Helpful
    • Not helpful
    • Only read

    滑鼠選中內容,快速回饋問題

    滑鼠選中存在疑惑的內容,即可快速回饋問題,我們將會跟進處理。

    不再提示

    10s後關閉

    Get
    Help
    Online Support
    Professional technical support is provided to quickly help you solve problems.
    Online support is available from 9:00-12:00 and 13:30-17:30 on weekdays.
    Page Feedback
    You can provide suggestions and feedback for the current web page.
    Pre-Sales Consultation
    Business Consultation
    Business: international@fanruan.com
    Support: support@fanruan.com
    Page Feedback
    *Problem Type
    Cannot be empty
    Problem Description
    0/1000
    Cannot be empty

    Submitted successfully

    Network busy