Technical interview questions for software engineers — languages, databases, web, cloud, DevOps, and fundamentals. Browse all topics.

  • PHP Interview Questions

  • OOP Interview Questions

  • jQuery Interview Questions

  • MySQL Interview Questions

  • JavaScript Interview Questions

  • HR Interview Questions

  • HTML Interview Questions

  • C/C++ Interview Questions

  • Showing posts with label Regular Expressions. Show all posts
    Showing posts with label Regular Expressions. Show all posts

    Regular expression find String,Word,Numbers in String

    Regular expression find string,word,numbers in string.
    In this section,I will explain how to find words,string,numbers in string using Regular expression.
    It is very easy to match strings or patterns of characters in php using regular expresions.
    A regular expression provides a matching strings of word,particular characters, numbers,or patterns of characters.Abbreviations for `regular expression` includes `regex` and `regexp`

    Example 1:
    //Regular expression find word in string
     In first example, we are using Regular expression to fing word in string using `\b`.
    `\b` allows you to find a perticular word only using a regular expression in the form of \bword\b.
    <?php
    $name = 'I have 6 years of exprience';
    preg_match( '/\byears\b/', $name, $match );
    echo $match[0];
    ?>
    Output: years


    Bookmark and Share

    Regular expression Basics in php

    Regular expression Basics in php:
    In this article ,i will show how to use regular expressions in php.

     \char escape char

      .            Any single character

     [chars]       One of following chars

     [^chars]      None of following chars

     text1|text2   text1 or text2

     ? 0 or 1 of the preceding text

     * 0 or N of the preceding text  (hungry)

     + 1 or N of the preceding text

     Example: (.+)\.html? matches test.htm and test.html

     (text)  Grouping of text

     Example:  ^(.*)\.html foo.php?bar=$1

      ^    Start of line anchor

      $    End   of line anchor

     Example: ^test(.*) matches test and test1 but not ttest
      (.*)1$ matches a1 and b1, but not test


    Bookmark and Share