File size: 2,253 Bytes
a5e8d12
530452f
a5e8d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530452f
a5e8d12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
530452f
a5e8d12
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
import re

def is_newline_after_text(text1, text2):
    """
    Checks if text1 is in text2 and if the next non-space character after text1 is a newline.

    Args:
        text1: The text to search for.
        text2: The text to search within.

    Returns:
        A tuple: (True/False if text1 is found, True/False if next char is newline, or None if not found)
    """

    match = re.search(re.escape(text1), text2)  #escape text1 to handle special characters

    if match:
        # Find the next non-space character
        next_char_index = match.end()
        while next_char_index < len(text2) and text2[next_char_index].isspace():
            next_char_index += 1

        if text2[next_char_index:next_char_index+2] == r'\n':
            print("newline found")
        if next_char_index < len(text2) and text2[next_char_index:next_char_index+2] == r'\n':
            return True

    return False

def is_newline_after_text_2(text1, text2):
    """
    Checks if text1 is in text2 and if the next non-space character after text1 is a newline.

    Args:
        text1: The text to search for.
        text2: The text to search within.

    Returns:
       True if next char is newline
    """
    text2 = text2.replace("\n", "\\n")
    
    ater_text = text2.split(text1)
    if len(ater_text) > 1:
        ater_text = ater_text[1].lstrip()  # Remove spaces
        if ater_text.startswith('\n'):
            return True
    return False

# Example usage:
text1 = "hello"
text2 = "some text hello \nmore text"
result = is_newline_after_text_2(text1, text2)
print(f"Next char is newline: {result}\n")

text1 = "hello"
text2 = "some text hello more text"
result = is_newline_after_text_2(text1, text2)
print(f"Next char is newline: {result}\n")

text1 = "hello"
text2 = "some text hello   \nmore text"
result = is_newline_after_text_2(text1, text2)
print(f"Next char is newline: {result}\n")

text1 = "hello"
text2 = "some text hello\t\nmore text" #test tab space before newline
result = is_newline_after_text_2(text1, text2)
print(f"Next char is newline: {result}\n")

text1 = "hello." #test special characters
text2 = "some text hello. \nmore text"
result = is_newline_after_text_2(text1, text2)
print(f"Next char is newline: {result}\n")