Skip to content
Related Articles

Related Articles

Improve Article

Find the previous occurrence of pattern in string in Julia – findprev() Method

  • Last Updated : 26 Mar, 2020
Geek Week

The findprev() is an inbuilt function in julia which is used to return the previous occurrence of the specified pattern in specified string starting from specified position.

Syntax:
findnprev(pattern::AbstractString, string::AbstractString, start::Integer)

Parameters:

  • pattern::AbstractString: Specified pattern
  • string::AbstractString: Specified string
  • start::Integer: It is the start position before which matching going to be performed.

Returns: It returns the previous occurrence of the specified pattern in a specified string starting from the specified position.

Example 1:






# Julia program to illustrate 
# the use of String findprev() method
   
# Here the pattern is "g", String is
# "geeks" and position is 3
Println(findprev("g", "geeks", 3))
  
# Here the pattern is "G", String is
# "GeeksforGeeks" and position is 10
Println(findprev("G", "GeeksforGeeks", 10))
  
# Here the pattern is "for", String is
# "GeeksforGeeks" and position is 8
Println(findprev("for", "GeeksforGeeks", 8))
  
# Here the pattern is "k", String is
# "GeeksforGeeks" and position is 7
Println(findprev("k", "GeeksforGeeks", 7))

Output:

Example 2:




# Julia program to illustrate 
# the use of String findprev() method
   
# Here the pattern is "23", String is
# "12345" and position is 5
Println(findprev("23", "12345", 5))
  
# Here the pattern is "23", String is
# "12345" and position is 4
Println(findprev("23", "12345", 4))
  
# Here the pattern is "3", String is
# "123123" and position is 6
Println(findprev("3", "123123", 6))
  
# Here the pattern is "123", String is
# "123123123" and position is 7
Println(findprev("123", "123123123", 7))

Output:




My Personal Notes arrow_drop_up
Recommended Articles
Page :